Module: Missions::DSL::EventHandler

Includes:
Helpers
Defined in:
lib/missions/dsl/event_handler.rb

Overview

Mission related event handlers XXX rename these methods

Class Method Summary collapse

Methods included from Helpers

#dsl_module_for, included, #is_dsl_category?

Class Method Details

.on_event_add_role(args = {}) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/missions/dsl/event_handler.rb', line 39

def self.on_event_add_role(args={})
  event = args[:event] || args['event']
  role  = args[:role]  || args['role']
  case event
  when 'registered_user' then
    proc { |event|
      user_id = event.users_event_args[1].id
      node.invoke('users::add_role', user_id, role)
    }
  else
    nil
  end
end

.on_event_create_entity(args = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/missions/dsl/event_handler.rb', line 16

def self.on_event_create_entity(args={})
  event       = args[:event]       || args['event']
  entity_type = args[:entity_type] || args['entity_type']
  id          = args[:id]          || args['id']
  case event
  when 'registered_user' then
    proc { |event|
      args[:id]      = id || Motel.gen_uuid
      args[:user_id] = event.users_event_args[1].id
      entity = entity_type == 'Manufactured::Ship' ?
          Manufactured::Ship.new(args) :
          Manufactured::Station.new(args)

      # TODO only if ship does not exist
      node.invoke('manufactured::create_entity', entity)
    }

  else
    nil

  end
end