Class: Armature::Puppetfile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache) ⇒ Puppetfile

Returns a new instance of Puppetfile.



5
6
7
8
9
10
# File 'lib/armature/puppetfile.rb', line 5

def initialize(cache)
  @cache = cache
  @results = {}
  @logger = Logging.logger[self]
  @forge_url = "https://forge.puppet.com"
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



3
4
5
# File 'lib/armature/puppetfile.rb', line 3

def results
  @results
end

Instance Method Details

#_mod_forge(full_name, name, version = :latest) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/armature/puppetfile.rb', line 44

def _mod_forge(full_name, name, version=:latest)
  if version == nil || version == {}
    version = "latest"
  else
    version = version.to_s
  end

  repo = Repo::Forge.from_url(@cache, @forge_url, full_name)
  ref = repo.general_ref(version)
  @logger.debug("mod #{name}: #{ref}")
  @results[name] = { :name => name, :ref => ref }
end

#_mod_git(name, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/armature/puppetfile.rb', line 57

def _mod_git(name, options={})
  options = Armature::Util.process_options(options, {
    :commit => nil,
    :tag => nil,
    :branch => nil,
    :ref => nil,
  }, {
    :git => nil,
  })

  repo = Repo::Git.from_url(@cache, options[:git])
  ref = nil

  if options[:commit]
    if ref
      raise "Module #{name} has more than one of :commit, :tag, :branch, or :ref"
    end
    ref = repo.identity_ref(options[:commit])
  end

  if options[:tag]
    if ref
      raise "Module #{name} has more than one of :commit, :tag, :branch, or :ref"
    end
    ref = repo.tag_ref(options[:tag])
  end

  if options[:branch]
    if ref
      raise "Module #{name} has more than one of :commit, :tag, :branch, or :ref"
    end
    ref = repo.branch_ref(options[:branch])
  end

  if options[:ref]
    if ref
      raise "Module #{name} has more than one of :commit, :tag, :branch, or :ref"
    end
    ref = repo.general_ref(options[:ref])
  end

  if ! ref
    ref = repo.branch_ref("master")
  end

  @logger.debug("mod #{name}: #{ref}")
  @results[name] = { :name => name, :ref => ref }
end

#forge(url) ⇒ Object



18
19
20
# File 'lib/armature/puppetfile.rb', line 18

def forge(url)
  @forge_url = url.chomp("/")
end

#include(path) ⇒ Object

FIXME this will have access to @cache and @results



13
14
15
16
# File 'lib/armature/puppetfile.rb', line 13

def include(path)
  instance_eval(IO.read(path), path)
  @results
end

#mod(full_name, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/armature/puppetfile.rb', line 22

def mod(full_name, options={})
  name = full_name.split("-", 2).last()
  Armature::Environments.assert_valid_module_name(name)

  if @results[name]
    raise "Module #{name} declared twice"
  end

  is_forge = options.is_a?(Symbol) \
    || options.is_a?(String) \
    || options == {} \
    || options == nil

  if is_forge
    _mod_forge(full_name, name, options)
  elsif options[:git]
    _mod_git(name, options)
  else
    raise "Invalid mod call: #{full_name} #{options}"
  end
end