Class: EventRouter::Destination
- Inherits:
-
Object
- Object
- EventRouter::Destination
- Defined in:
- lib/event_router/destination.rb
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
Constants
{ # Defaults to the event name, e.g "order_placed" handler_method: nil, # Defaults to not fetch before scheduling the job. prefetch_payload: false, # Defaults to destination name, e.g "#{name}_payload" payload_method: nil }.freeze
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Attributes.
-
#handler_method ⇒ Object
readonly
Attributes.
-
#name ⇒ Object
readonly
Attributes.
-
#options ⇒ Object
readonly
Attributes.
-
#payload_method ⇒ Object
readonly
Attributes.
-
#prefetch_payload ⇒ Object
readonly
Attributes.
Instance Method Summary collapse
- #extra_payload(event) ⇒ Object
-
#initialize(name, handler:, **opts) ⇒ Destination
constructor
Methods.
- #prefetch_payload? ⇒ Boolean
- #process(event, payload) ⇒ Object
Constructor Details
#initialize(name, handler:, **opts) ⇒ Destination
Methods
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/event_router/destination.rb', line 21 def initialize(name, handler:, **opts) opts = DEFAULT_ATTRIBUTES.merge(opts) @name = name @handler = handler @handler_method = opts.delete(:handler_method) @prefetch_payload = opts.delete(:prefetch_payload) @payload_method = opts.delete(:payload_method) || "#{name}_payload" @options = opts end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def handler @handler end |
#handler_method ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def handler_method @handler_method end |
#name ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def @options end |
#payload_method ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def payload_method @payload_method end |
#prefetch_payload ⇒ Object (readonly)
Attributes
6 7 8 |
# File 'lib/event_router/destination.rb', line 6 def prefetch_payload @prefetch_payload end |
Instance Method Details
#extra_payload(event) ⇒ Object
44 45 46 47 48 |
# File 'lib/event_router/destination.rb', line 44 def extra_payload(event) return nil unless event.respond_to?(payload_method) event.send(payload_method) end |
#prefetch_payload? ⇒ Boolean
40 41 42 |
# File 'lib/event_router/destination.rb', line 40 def prefetch_payload? @prefetch_payload end |
#process(event, payload) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/event_router/destination.rb', line 32 def process(event, payload) handler.send( handler_method || event.name, event: event, payload: payload ) end |