Sha256: 2d1ed9987c546dedad2aee3a86505c013ccd43d4659eb926b7025c558a5d1900

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

class EcoRake
  module Lib
    module Files
      class Sftp < EcoRake::Lib::BaseTask
        FORWARD_RULES = {
          enviro:   ->(enviro) { "-#{enviro}" },
          folder:   ->(folder) { "-local-folder #{folder}"},
          list:     '-list',
          get_last: '-get-last',
          get:      '-get',
          archive:  '-archive'
        }.freeze

        options_with_defaults true

        option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true
        option '-d', '--folder NAME', default: '.', desc: 'Source local folder'
        option '-l', '--list', TrueClass, desc: 'Lists available CSV feed files'
        option '-g', '--get', TrueClass, desc: 'Gets all available CSV feed files'
        option '-t', '--get-last', TrueClass, desc: 'Gets the last available CSV feed file'
        option '-a', '--archive', TrueClass, desc: "Moves the remote CSV feed files to the '/Archive' folder"

        option_forwarding(**FORWARD_RULES)

        # attr_const :target_enviro, required: true
        # option_reopen :enviro, default_lookup: :target_enviro

        def task(*_args)
          sh sftp_command
        end

        private

        def sftp_command
          cmd  = [base_command]
          cmd << forward_option(:folder)
          cmd << forward_options(:list, :get_last, :get, :archive).compact.first || '-list'
          cmd << '-no-people'
          cmd = yield(cmd) if block_given?
          string_cmd(*cmd)
        end

        def base_command
          string_cmd(ruby_runner, forward_option(:enviro), '-sftp')
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eco-rake-0.1.4 lib/eco-rake/lib/files/sftp.rb
eco-rake-0.1.3 lib/eco-rake/lib/files/sftp.rb
eco-rake-0.1.2 lib/eco-rake/lib/files/sftp.rb
eco-rake-0.1.1 lib/eco-rake/lib/files/sftp.rb