Class: Consist::Commands::Upload

Inherits:
Object
  • Object
show all
Includes:
Erbable
Defined in:
lib/consist/commands/upload.rb

Instance Method Summary collapse

Methods included from Erbable

#erb_template, included

Constructor Details

#initialize(command) ⇒ Upload

Returns a new instance of Upload.



8
9
10
# File 'lib/consist/commands/upload.rb', line 8

def initialize(command)
  @command = command
end

Instance Method Details

#perform!(executor) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/consist/commands/upload.rb', line 12

def perform!(executor)
  # rubocop:disable Style/ClassEqualityComparison
  if @command[:local_file].class == Symbol
    puts "---> Uploading defined file #{@command[:local_file]}"
    target_file = Consist.files.detect { |f| f[:id] == @command[:local_file] }
    raise "\n\nNo declared file of ID `#{@command[:local_file]}`" unless target_file

    contents = StringIO.new(erb_template(target_file[:contents]))
    upload_defined_file(executor, contents, @command[:remote_path])
  else
    local_path = File.expand_path("../steps/#{@id}/#{@command[:local_file]}", __dir__)
    upload(executor, local_path, @command[:remote_path])
  end
  # rubocop:enable Style/ClassEqualityComparison
end

#upload(executor, local_path, remote_path) ⇒ Object



28
29
30
# File 'lib/consist/commands/upload.rb', line 28

def upload(executor, local_path, remote_path)
  executor.send(:upload!, local_path, remote_path, interaction_handler: Consist::Commands::StreamLogger.new)
end

#upload_defined_file(executor, contents, remote_path) ⇒ Object



32
33
34
# File 'lib/consist/commands/upload.rb', line 32

def upload_defined_file(executor, contents, remote_path)
  executor.upload! contents, remote_path, interaction_handler: Consist::Commands::StreamLogger.new
end