Module: Puppetfiler

Defined in:
lib/puppetfiler.rb,
lib/puppetfiler/cli.rb,
lib/puppetfiler/mod.rb,
lib/puppetfiler/fixture.rb,
lib/puppetfiler/version.rb,
lib/puppetfiler/metadata.rb,
lib/puppetfiler/puppetfile.rb

Defined Under Namespace

Classes: CLI, Fixture, Metadata, Mod, Puppetfile

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.check(type = nil, target = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/puppetfiler.rb', line 30

def self.check(type = nil, target = nil)
    type, target = detect(type, target)

    case type
    when :puppetfile
        t = Puppetfiler::Puppetfile.new(target)
    when :metadata
        # TODO see below
        fail 'Checking metadata.json for version range updates is not implemented yet'
    else fail "Unkown type: #{type}"
    end

    # TODO the updates should be collected asynchronously to
    # speed up the process
    return t.updates
end

.detect(type = nil, target = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppetfiler.rb', line 9

def self.detect(type = nil, target = nil)
    if (type.nil? && !target.nil?) || (!type.nil? && target.nil?)
        fail 'Type and target are required to bet both set'
    elsif !type.nil? && !target.nil?
        return type, target
    end

    {
        :puppetfile => %w{Puppetfile},
        :metadata   => %w{metadata.json},
    }.each do |type, targets|
        targets.each do |target|
            if File.exists?(target)
                return type, target
            end
        end
    end

    fail 'No valid target found, aborting'
end

.fixture(type = nil, target = nil, modifier = {}, stdout = false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppetfiler.rb', line 47

def self.fixture(type = nil, target = nil, modifier = {}, stdout = false)
    type, target = detect(type, target)

    case type
    when :puppetfile
        f = Puppetfiler::Puppetfile.new(target)
    when :metadata
        f = Puppetfiler::Metadata.new(File.new(target))
    else fail "Unkown type: #{type}"
    end

    f = f.fixture(modifier).to_yaml

    if stdout
        puts f
    else
        File.write('.fixtures.yml', f)
    end
end