Class: Rapid::Services::Handler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ury_rapid/services/handler.rb

Overview

Base class for request and response handlers.

See Rapid::Services::Requests::Handler and Rapid::Services::Responses::Handler for the more specific base classes.

Direct Known Subclasses

Requests::Handler, Responses::Handler

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(in_parent) ⇒ Handler

Initialises the Handler

Examples:

Initialising a Handler with a parent Requester.

queue = EventMachine::Queue.new
requester = Rapid::Baps::Requests::Requester.new(queue)
handler = Rapid::Baps::Requests::Handler.new(requester)

24
25
26
# File 'lib/ury_rapid/services/handler.rb', line 24

def initialize(in_parent)
  @parent = in_parent
end

Class Method Details

.def_targets(*targets) ⇒ Object


36
37
38
# File 'lib/ury_rapid/services/handler.rb', line 36

def self.def_targets(*targets)
  const_set('TARGETS', targets)
end

.register_into(set) ⇒ Object

Adds this handler's targets into the given handler set.


53
54
55
56
57
58
# File 'lib/ury_rapid/services/handler.rb', line 53

def self.register_into(set)
  self::TARGETS.each do |target|
    set.register_handler(target, ->(*args) { new(set, *args).run })
    set.log(:info, "Registered #{self} for #{target}.")
  end
end

.targets?Boolean


48
49
50
# File 'lib/ury_rapid/services/handler.rb', line 48

def self.targets?
  defined?(self::TARGETS) && !(self::TARGETS.empty?)
end

.use_poster(poster_class, *actions) ⇒ Object


40
41
42
43
44
45
46
# File 'lib/ury_rapid/services/handler.rb', line 40

def self.use_poster(poster_class, *actions)
  actions.each do |action|
    define_method(action) do |object, payload|
      poster_class.post(payload, self, object)
    end
  end
end

Instance Method Details

#targetsObject


32
33
34
# File 'lib/ury_rapid/services/handler.rb', line 32

def targets
  self.class::TARGETS
end