Sha256: 4900b32fa8f4fd6110fbc7921c17120f47b41e0726dfedbcd6ba89877aeb8514

Contents?: true

Size: 738 Bytes

Versions: 11

Compression:

Stored size: 738 Bytes

Contents

require "yaml"

class TerraspaceBundler::Lockfile
  class Yamler
    def initialize(mods)
      @mods = mods.sort_by(&:name)
    end

    def dump
      YAML.dump(data.deep_stringify_keys)
    end

    def data
      @mods.inject({}) do |acc, mod|
        acc.merge(item(mod))
      end
    end

    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

    def write
      IO.write(TB.config.lockfile, dump)
    end

    class << self
      def write(mods)
        new(mods).write
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
terraspace-bundler-0.5.0 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.4.4 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.4.3 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.4.2 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.4.1 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.4.0 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.3.4 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.3.3 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.3.2 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.3.1 lib/terraspace_bundler/lockfile/yamler.rb
terraspace-bundler-0.3.0 lib/terraspace_bundler/lockfile/yamler.rb