Class: Puppetfile
- Inherits:
-
Object
- Object
- Puppetfile
- Defined in:
- lib/release_manager/puppetfile.rb
Constant Summary collapse
- BUMP_TYPES =
%w{patch minor major}
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#data ⇒ Object
Returns the value of attribute data.
-
#modules ⇒ Array[ControlMod]
-
a list of control mod objects.
-
-
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
-
#puppetmodule ⇒ Object
Returns the value of attribute puppetmodule.
Class Method Summary collapse
Instance Method Summary collapse
- #add_module(name, metadata) ⇒ Object
- #bump(mod_name, type = 'patch') ⇒ Object
- #commit(message) ⇒ Object
- #current_branch ⇒ Object
-
#find_mod(name) ⇒ Object
ControlMod - a ControlMod object.
- #find_mods(names) ⇒ Object
- #forge(name, *args) ⇒ Object
- #git_command ⇒ Object
-
#initialize(puppetfile = 'Puppetfile') ⇒ Puppetfile
constructor
A new instance of Puppetfile.
- #mod(name, *args) ⇒ Object
- #push(remote, branch, force = false) ⇒ Object
- #source ⇒ Object
- #to_json(pretty = false) ⇒ Object
- #to_s ⇒ Object
- #write_source(mod_name, src, branch = nil) ⇒ ControlMod
- #write_to_file ⇒ Object
- #write_version(mod_name, version) ⇒ Object
Constructor Details
#initialize(puppetfile = 'Puppetfile') ⇒ Puppetfile
Returns a new instance of Puppetfile.
12 13 14 15 |
# File 'lib/release_manager/puppetfile.rb', line 12 def initialize(puppetfile = 'Puppetfile') @puppetfile = puppetfile @puppetmodule = PuppetModule.new(base_path) end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
8 9 10 |
# File 'lib/release_manager/puppetfile.rb', line 8 def base_path @base_path end |
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/release_manager/puppetfile.rb', line 8 def data @data end |
#modules ⇒ Array[ControlMod]
Returns - a list of control mod objects.
55 56 57 |
# File 'lib/release_manager/puppetfile.rb', line 55 def modules @modules end |
#puppetfile ⇒ Object
Returns the value of attribute puppetfile.
8 9 10 |
# File 'lib/release_manager/puppetfile.rb', line 8 def puppetfile @puppetfile end |
#puppetmodule ⇒ Object
Returns the value of attribute puppetmodule.
8 9 10 |
# File 'lib/release_manager/puppetfile.rb', line 8 def puppetmodule @puppetmodule end |
Class Method Details
.from_string(s) ⇒ Object
63 64 65 66 67 |
# File 'lib/release_manager/puppetfile.rb', line 63 def self.from_string(s) instance = new instance.data = s instance end |
.to_puppetfile(json_data) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/release_manager/puppetfile.rb', line 130 def self.to_puppetfile(json_data) obj = JSON.parse(json_data) mods = obj.collect do |name, | name = "mod '#{name}'," data = .sort.map { |k, v| ":#{k} => '#{v}'" }.join(",\n\ ") "#{name}\n #{data}\n" end.join("\n") mods end |
Instance Method Details
#add_module(name, metadata) ⇒ Object
38 39 40 |
# File 'lib/release_manager/puppetfile.rb', line 38 def add_module(name, ) modules[name] = ControlMod.new(name, ) end |
#bump(mod_name, type = 'patch') ⇒ Object
108 109 110 111 112 |
# File 'lib/release_manager/puppetfile.rb', line 108 def bump(mod_name, type = 'patch') raise "Invalid type, must be one of #{BUMP_TYPES}" unless BUMP_TYPES.include?(type) mod = find_mod(mod_name) find_mod(mod_name).send("bump_#{type}_version") end |
#commit(message) ⇒ Object
29 30 31 32 |
# File 'lib/release_manager/puppetfile.rb', line 29 def commit() puts `#{git_command} add #{puppetfile}` puts `#{git_command} commit -n -m "[ReleaseManager] - #{message}"` end |
#current_branch ⇒ Object
34 35 36 |
# File 'lib/release_manager/puppetfile.rb', line 34 def current_branch `#{git_command} rev-parse --abbrev-ref HEAD` end |
#find_mod(name) ⇒ Object
Returns ControlMod - a ControlMod object.
83 84 85 86 87 88 89 90 |
# File 'lib/release_manager/puppetfile.rb', line 83 def find_mod(name) mod_name = name.strip.downcase mod = modules[mod_name] || modules.find{ |module_name, mod| mod.repo =~ /#{mod_name}/i } raise InvalidModuleNameException.new("Invalid module name #{name}, cannot locate in Puppetfile") unless mod # since find returns an array we need to grab the element ouf of the array first return mod.last if mod.instance_of?(Array) mod end |
#find_mods(names) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/release_manager/puppetfile.rb', line 71 def find_mods(names) mods = {} return mods if names.nil? names.each do | mod_name | m = find_mod(mod_name) mods[m.name] = m end mods end |
#forge(name, *args) ⇒ Object
144 145 146 |
# File 'lib/release_manager/puppetfile.rb', line 144 def forge(name, *args) # skip this for now end |
#git_command ⇒ Object
25 26 27 |
# File 'lib/release_manager/puppetfile.rb', line 25 def git_command "git --work-tree=#{base_path} --git-dir=#{base_path}/.git" end |
#mod(name, *args) ⇒ Object
140 141 142 |
# File 'lib/release_manager/puppetfile.rb', line 140 def mod(name, *args) @modules[name] = ControlMod.new(name, args.flatten.first) end |
#push(remote, branch, force = false) ⇒ Object
42 43 44 45 |
# File 'lib/release_manager/puppetfile.rb', line 42 def push(remote, branch, force = false) opts = force ? '-f' : '' `#{git_command} push #{remote} #{branch} #{opts}` end |
#source ⇒ Object
17 18 19 |
# File 'lib/release_manager/puppetfile.rb', line 17 def source puppetmodule.source end |
#to_json(pretty = false) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/release_manager/puppetfile.rb', line 114 def to_json(pretty = false) if pretty JSON.pretty_generate(modules) else modules.to_json end end |
#to_s ⇒ Object
126 127 128 |
# File 'lib/release_manager/puppetfile.rb', line 126 def to_s modules.collect {|n, mod| mod.to_s }.join("\n\n") end |
#write_source(mod_name, src, branch = nil) ⇒ ControlMod
101 102 103 104 105 106 |
# File 'lib/release_manager/puppetfile.rb', line 101 def write_source(mod_name, src, branch = nil) mod = find_mod(mod_name) mod.pin_url(src) mod.pin_branch(branch) if branch mod end |
#write_to_file ⇒ Object
122 123 124 |
# File 'lib/release_manager/puppetfile.rb', line 122 def write_to_file File.write(puppetfile, to_s) end |
#write_version(mod_name, version) ⇒ Object
92 93 94 95 |
# File 'lib/release_manager/puppetfile.rb', line 92 def write_version(mod_name, version) mod = find_mod(mod_name) mod.pin_version(version) end |