Class: Executo::Command

Inherits:
Object
  • Object
show all
Includes:
CommandDsl, TaggedLogger
Defined in:
lib/executo/command.rb

Direct Known Subclasses

ImapSyncTest

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Command

Returns a new instance of Command.



10
11
12
13
14
15
# File 'lib/executo/command.rb', line 10

def initialize(*args)
  @executo_id = args.first&.delete(:id) || SecureRandom.uuid
  @errors = ActiveModel::Errors.new(self)
  @parameter_values = args.first&.delete(:parameter_values) || {}
  super(*args)
end

Instance Attribute Details

#executo_idObject (readonly)

Returns the value of attribute executo_id.



8
9
10
# File 'lib/executo/command.rb', line 8

def executo_id
  @executo_id
end

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



8
9
10
# File 'lib/executo/command.rb', line 8

def exitstatus
  @exitstatus
end

#parameter_valuesObject (readonly)

Returns the value of attribute parameter_values.



8
9
10
# File 'lib/executo/command.rb', line 8

def parameter_values
  @parameter_values
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/executo/command.rb', line 8

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



8
9
10
# File 'lib/executo/command.rb', line 8

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



8
9
10
# File 'lib/executo/command.rb', line 8

def stdout
  @stdout
end

Class Method Details

.process_feedback(feedback, results) ⇒ Object



49
50
51
52
53
# File 'lib/executo/command.rb', line 49

def process_feedback(feedback, results)
  cmd = new(feedback['arguments'].merge(id: feedback['id']))
  cmd.setup_logger(feedback['id'])
  cmd.process_results(results.symbolize_keys)
end

Instance Method Details

#callObject



17
18
19
20
21
# File 'lib/executo/command.rb', line 17

def call
  raise 'missing target' unless target

  perform
end

#process_results(results) ⇒ Object



23
24
25
26
27
# File 'lib/executo/command.rb', line 23

def process_results(results)
  state = results[:state]
  logger.debug("Processing #{state} results")
  public_send(state.to_sym, results) if respond_to?(state.to_sym)
end

#setup_logger(id) ⇒ Object



29
30
31
32
# File 'lib/executo/command.rb', line 29

def setup_logger(id)
  logger_add_tag(self.class.name)
  logger_add_tag(id)
end