Sha256: a027e215dba6b6c1fe40b65a4b93354706d5d0312fe9152e89576c8653a6f7c6

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module TerraspaceBundler
  class Updater
    include Logging

    def initialize(options={})
      @options = options
      @mod_name = @options[:mod]
    end

    def run(without_install: false)
      Setup.new(@options).setup!
      puts "Bundling modules from #{TB.config.terrafile}..."

      if update_one?
        update_one
      else
        update_all
      end
      unless without_install
        Installer.new(@options.merge(download: false)).run
      end
    end

    def update_one?
      @mod_name && File.exist?(TB.config.lockfile)
    end

    def update_one
      meta = Dsl.new.run
      mods = meta[:mods].map { |data| Mod.new(data, meta[:global]) }
      mod = mods.find { |m| m.name == @mod_name }
      unless mod
        logger.error "No module #{@mod_name} found in your Terrafile"
        exit 1
      end
      mod.sync
      Lockfile.new.update_one(mod)
    end

    def update_all
      meta = Dsl.new.run
      mods = meta[:mods].map { |data| Mod.new(data, meta[:global]) }
      mods.each do |mod|
        mod.sync
      end
      Lockfile.new(mods).create
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraspace-bundler-0.1.0 lib/terraspace_bundler/updater.rb