Sha256: 96a1ab9ed609baeda839817ead7b66afb301477b28910675027128f699ce0696

Contents?: true

Size: 1.76 KB

Versions: 3

Compression:

Stored size: 1.76 KB

Contents

require 'fileutils'
require 'yaml'

module Jack
  module Config
    class Download < Transmit
      include Util

      attr_reader :current_path, :current_name

      def initialize(options={})
        super
        @current_path = "#{@saved_configs}/current-#{timestamp}.cfg.yml"
        @current_name = extract_name(@current_path)
        EbConfig::Update.new(env_name: @env_name).sync unless options[:noop]
      end

      def run
        download
      end

      def download
        get_current_cfg
        copy_to_local_cfg
        clean
        UI.say "Config downloaded to #{@local_config_path}".colorize(:green)
      end

      def get_current_cfg
        UI.say "Downloading config file..."
        eb_config_save
      end

      # for specs
      def eb_config_save
        do_cmd("eb config save --cfg #{current_name} #{@env_name}", @options)
      end

      def copy_to_local_cfg
        UI.say "Writing to local config file: #{@local_config_path}"
        dirname = File.dirname("#{@root}/#{@local_config_path}")
        FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
        do_copy_to_local_cfg
      end

      # for specs
      def do_copy_to_local_cfg
        return if @options[:noop]
        local_path = "#{@root}/#{@local_config_path}"
        FileUtils.cp(@current_path, local_path) 
        YamlFormatter.new.process(local_path)
      end

      # remove both the local download file and remote eb config
      def clean(silent=false)
        return if @options[:dirty]
        UI.say "Cleaning up eb remote config and local files" unless silent
        eb.delete_configuration_template(
          application_name: @app_name,
          template_name: current_name
        ) unless @options[:noop]
        FileUtils.rm_f(@current_path)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jack-eb-0.0.7 lib/jack/config/download.rb
jack-eb-0.0.6 lib/jack/config/download.rb
jack-eb-0.0.4 lib/jack/config/download.rb