Class: Manufactured::Events::SystemJump

Inherits:
Omega::Server::Event show all
Defined in:
lib/manufactured/events/system_jump.rb

Constant Summary collapse

TYPE =
:system_jump

Instance Attribute Summary collapse

Attributes inherited from Omega::Server::Event

#handlers, #id, #registry, #timestamp, #type

Instance Method Summary collapse

Methods inherited from Omega::Server::Event

#handlers_json, #invoke, json_create, #json_data, #should_exec?, #time_elapsed?, #to_s

Constructor Details

#initialize(args = {}) ⇒ SystemJump

System Jump Event intializer


22
23
24
25
26
27
# File 'lib/manufactured/events/system_jump.rb', line 22

def initialize(args={})
  attr_from_args args, :old_system => nil,
                       :entity     => nil
  id = "#{TYPE}-#{entity ? entity.id : nil}"
  super(:id => id, :type => TYPE.to_s)
end

Instance Attribute Details

#entityObject

Entity which made the jump. Entity's parent property will be the new system it is in


16
17
18
# File 'lib/manufactured/events/system_jump.rb', line 16

def entity
  @entity
end

#old_systemObject

System which entity jumped from


19
20
21
# File 'lib/manufactured/events/system_jump.rb', line 19

def old_system
  @old_system
end

Instance Method Details

#event_argsObject


29
30
31
# File 'lib/manufactured/events/system_jump.rb', line 29

def event_args
  [entity, old_system]
end

#to_json(*a) ⇒ Object

Convert event to json representation and return it


49
50
51
52
53
54
# File 'lib/manufactured/events/system_jump.rb', line 49

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       => {:old_system => @old_system, :entity => @entity}
  }.to_json(*a)
end

#trigger_handler?(handler) ⇒ Boolean

Assuming we're only getting Manufactured::EventHandler instances here


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/manufactured/events/system_jump.rb', line 34

def trigger_handler?(handler)
  specifier = handler.event_args[0]
  target    = handler.event_args[1]

  case specifier
  when 'to'
    entity.parent_id == target
  when 'from'
    old_system.id == target
  else
    false
  end
end