Class: Puppetfiler::Puppetfile

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetfiler/puppetfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = 'Puppetfile') ⇒ Puppetfile

Returns a new instance of Puppetfile.



9
10
11
12
13
14
15
# File 'lib/puppetfiler/puppetfile.rb', line 9

def initialize(path = 'Puppetfile')
    @modules    = {}
    @repos      = {}
    @puppetfile = path

    self.evaluate
end

Instance Attribute Details

#modulesObject (readonly)

Returns the value of attribute modules.



5
6
7
# File 'lib/puppetfiler/puppetfile.rb', line 5

def modules
  @modules
end

#puppetfileObject (readonly)

Returns the value of attribute puppetfile.



7
8
9
# File 'lib/puppetfiler/puppetfile.rb', line 7

def puppetfile
  @puppetfile
end

#reposObject (readonly)

Returns the value of attribute repos.



6
7
8
# File 'lib/puppetfiler/puppetfile.rb', line 6

def repos
  @repos
end

Instance Method Details

#evaluateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppetfiler/puppetfile.rb', line 17

def evaluate
    if not File.exists?(@puppetfile)
        STDERR.puts "Puppetfile not found at path '#{@puppetfile}'"
        return nil
    end

    begin
        # TODO similar to Metadata, allow IO objects like File,
        # string or similar to be passed in instead of expecting
        # a path
        self.instance_eval(File.read(@puppetfile))
    rescue SyntaxError => error
        STDERR.puts "Puppetfile at path '#{@puppetfile}' is invalid:"
        STDERR.puts error
        return nil
    end
end

#fixture(modifiers = {}) ⇒ Object



61
62
63
# File 'lib/puppetfiler/puppetfile.rb', line 61

def fixture(modifiers = {})
    Puppetfiler::Fixture.fixture(@modules, @repos, modifiers)
end

#updatesObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/puppetfiler/puppetfile.rb', line 35

def updates
    require 'concurrent'

    updates = {}

    mods = @modules.map do |name, mod|
        Concurrent::Future.execute do
            current = mod.version
            newest = mod.latest

            if not newest.eql?(current)
                updates[name] = {
                    :current => current,
                    :newest  => newest,
                }
            end
        end
    end

    # A timeout of 300 seconds per job should be plenty
    # TODO configurable timeout
    mods.each { |f| f.wait_or_cancel(300) }

    return updates
end