Class: Puppetfiler::Fixture

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

Class Method Summary collapse

Class Method Details

.fixture(modules, repos, modifiers = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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/fixture.rb', line 3

def self.fixture(modules, repos, modifiers = {})
    fixtures = {}

    %w{forge_modules repositories}.each do |k|
        modifiers[k] = {} if not modifiers.has_key?(k)
    end

    modules.each do |name, mod|
        short = name.split('/')[1]
        value = {
            'repo' => name,
            'ref'  => mod.version.to_s,
        }

        modifiers['forge_modules'].each do |modifier, merger|
            # TODO use x.match?(y) on ruby 2.4
            value.merge!(merger) if name =~ /#{modifier}/
        end

        fixtures['forge_modules'] = {} if not fixtures.has_key?('forge_modules')
        fixtures['forge_modules'][short] = value
    end

    repos.each do |name, hash|
        if hash.has_key?(:ref)
            content = {
                'repo' => hash[:uri],
                'ref'  => hash[:ref],
            }

            modifiers['repositories'].each do |modifier, merger|
                content.merge!(merger) if name =~ /#{modifier}/
            end
        else
            content = hash[:uri]

            modifiers['repositories'].each do |modifier, merger|
                if name =~ /#{modifier}/
                    if merger.is_a?(String)
                        content = merger
                    else
                        content = {
                            'repo' => hash[:uri],
                        }

                        content.merge!(merger)
                    end
                end
            end
        end

        fixtures['repositories'] = {} if not fixtures.has_key?('repositories')
        fixtures['repositories'][name] = content
    end

    return { 'fixtures' => fixtures }
end