Sha256: 6aa9c267507bb3d9a12d502fbe419d30132ea9efbd4828d0c129450546604333

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module TerraspaceBundler
  class Exporter
    include TB::Mod::PathConcern
    include TB::Util::Logging

    def initialize(options={})
      @options = options
    end

    def run
      purge_all
      mods.each do |mod|
        logger.info "Exporting #{mod.name}"
        purge(mod)
        export(mod)
      end
    end

    def mods
      mods = lockfile.mods
      if TB.update_mode? && !@options[:mods].empty?
        mods.select! { |mod| @options[:mods].include?(mod.name) }
      end
      mods
    end

    def export(mod)
      downloader = Mod::Downloader.new(mod)
      downloader.run
      downloader.switch_version(mod.sha)
      copy = Copy.new(mod)
      copy.mod
      copy.stacks
      logger.debug "Exported: #{copy.mod_path}"
    end

  private
    def purge_all
      return if TB.update_mode?
      return unless TB.config.export_purge
      FileUtils.rm_rf(TB.config.export_to)
    end

    def purge(mod)
      mod_path = get_mod_path(mod)
      FileUtils.rm_rf(mod_path)
    end

    def lockfile
      Lockfile.instance
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
terraspace-bundler-0.3.4 lib/terraspace_bundler/exporter.rb
terraspace-bundler-0.3.3 lib/terraspace_bundler/exporter.rb
terraspace-bundler-0.3.2 lib/terraspace_bundler/exporter.rb