Class: Missions::EventHandlers::DSL

Inherits:
Omega::Server::EventHandler show all
Defined in:
lib/missions/event_handler.rb

Overview

Subclasses Omega::Server::EventHandler to define a custom event handler which accepts / runs missions dsl methods

Instance Attribute Summary collapse

Attributes inherited from Omega::Server::EventHandler

#endpoint_id, #event_id, #event_type, #persist

Instance Method Summary collapse

Methods inherited from Omega::Server::EventHandler

#handlers_json, json_create, #json_data, #matches?

Constructor Details

#initialize(args = {}) ⇒ DSL


20
21
22
23
24
# File 'lib/missions/event_handler.rb', line 20

def initialize(args={})
  attr_from_args args,
                 :missions_callbacks => []
  super(args)
end

Instance Attribute Details

#missions_callbacksObject Also known as: handlers

Missions DSL callbacks registered with the event handler


15
16
17
# File 'lib/missions/event_handler.rb', line 15

def missions_callbacks
  @missions_callbacks
end

Instance Method Details

#exec(cb) ⇒ Object


26
27
28
# File 'lib/missions/event_handler.rb', line 26

def exec(cb)
  @missions_callbacks << cb
end

#invoke(*args) ⇒ Object

Make sure to have resolved mission dsl proxies before calling invoke


38
39
40
41
42
# File 'lib/missions/event_handler.rb', line 38

def invoke(*args)
  @missions_callbacks.each { |cb|
    cb.call *args
  }
end

#to_json(*a) ⇒ Object


30
31
32
33
34
35
# File 'lib/missions/event_handler.rb', line 30

def to_json(*a)
  { 'json_class' => self.class.name,
    'data'       =>
      json_data.merge({:missions_callbacks => missions_callbacks})
  }.to_json(*a)
end