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



53
54
55
# File 'lib/puppetfiler/puppetfile.rb', line 53

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
# File 'lib/puppetfiler/puppetfile.rb', line 35

def updates
    updates = {}

    @modules.each do |name, mod|
        current = mod.version
        newest = mod.latest

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

    return updates
end