Class: TerraspaceBundler::Lockfile::Yamler
- Inherits:
-
Object
- Object
- TerraspaceBundler::Lockfile::Yamler
- Defined in:
- lib/terraspace_bundler/lockfile/yamler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #dump ⇒ Object
-
#initialize(mods) ⇒ Yamler
constructor
A new instance of Yamler.
- #item(mod) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(mods) ⇒ Yamler
Returns a new instance of Yamler.
5 6 7 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 5 def initialize(mods) @mods = mods.sort_by(&:name) end |
Class Method Details
.write(mods) ⇒ Object
32 33 34 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 32 def write(mods) new(mods).write end |
Instance Method Details
#data ⇒ Object
13 14 15 16 17 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 13 def data @mods.inject({}) do |acc, mod| acc.merge(item(mod)) end end |
#dump ⇒ Object
9 10 11 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 9 def dump YAML.dump(data.deep_stringify_keys) end |
#item(mod) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 19 def item(mod) props = mod.props.dup # passthrough: name, url, version, ref, tag, branch etc props.delete(:name) # different structure in Terrafile.lock YAML props[:sha] ||= mod.latest_sha props.delete_if { |k,v| v.nil? } { mod.name => props } end |
#write ⇒ Object
27 28 29 |
# File 'lib/terraspace_bundler/lockfile/yamler.rb', line 27 def write IO.write(TB.config.lockfile, dump) end |