Class: Swarm::Observers::Logger

Inherits:
Base
  • Object
show all
Defined in:
lib/swarm/observers/logger.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#command

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Swarm::Observers::Base

Instance Attribute Details

#initial_workitemObject (readonly)

Returns the value of attribute initial_workitem.



8
9
10
# File 'lib/swarm/observers/logger.rb', line 8

def initial_workitem
  @initial_workitem
end

Instance Method Details

#after_actionObject



20
21
22
# File 'lib/swarm/observers/logger.rb', line 20

def after_action
  puts log_entry
end

#before_actionObject



10
11
12
13
14
# File 'lib/swarm/observers/logger.rb', line 10

def before_action
  return unless object

  @initial_workitem = object.workitem
end

#log_entryObject



16
17
18
# File 'lib/swarm/observers/logger.rb', line 16

def log_entry
  "[#{Time.now}]: #{action}; #{object_string}"
end

#object_stringObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/swarm/observers/logger.rb', line 24

def object_string
  return "No object" unless object

  object.reload!
  string = if object.is_a?(Swarm::Expression)
    "#{object.position}: #{object.command} #{object.arguments}"
  elsif object.is_a?(Swarm::Process)
    object.process_definition_name.to_s
  end
  if object.workitem != initial_workitem
    string += "; #{object.workitem}"
  end
  string
end