Class: Legion::Gaia::OutputRouter
- Inherits:
-
Object
- Object
- Legion::Gaia::OutputRouter
- Defined in:
- lib/legion/gaia/output_router.rb
Instance Attribute Summary collapse
-
#channel_registry ⇒ Object
readonly
Returns the value of attribute channel_registry.
-
#notification_gate ⇒ Object
readonly
Returns the value of attribute notification_gate.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Instance Method Summary collapse
-
#initialize(channel_registry:, renderer: nil, notification_gate: nil) ⇒ OutputRouter
constructor
A new instance of OutputRouter.
- #process_delayed ⇒ Object
- #route(output_frame) ⇒ Object
- #route_to(output_frame, channel_id:) ⇒ Object
Constructor Details
#initialize(channel_registry:, renderer: nil, notification_gate: nil) ⇒ OutputRouter
Returns a new instance of OutputRouter.
8 9 10 11 12 |
# File 'lib/legion/gaia/output_router.rb', line 8 def initialize(channel_registry:, renderer: nil, notification_gate: nil) @channel_registry = channel_registry @renderer = renderer @notification_gate = notification_gate end |
Instance Attribute Details
#channel_registry ⇒ Object (readonly)
Returns the value of attribute channel_registry.
6 7 8 |
# File 'lib/legion/gaia/output_router.rb', line 6 def channel_registry @channel_registry end |
#notification_gate ⇒ Object (readonly)
Returns the value of attribute notification_gate.
6 7 8 |
# File 'lib/legion/gaia/output_router.rb', line 6 def notification_gate @notification_gate end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
6 7 8 |
# File 'lib/legion/gaia/output_router.rb', line 6 def renderer @renderer end |
Instance Method Details
#process_delayed ⇒ Object
27 28 29 30 31 32 |
# File 'lib/legion/gaia/output_router.rb', line 27 def process_delayed return [] unless @notification_gate frames = @notification_gate.process_delayed frames.map { |frame| channel_registry.deliver(frame) } end |
#route(output_frame) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/gaia/output_router.rb', line 14 def route(output_frame) if @notification_gate decision = @notification_gate.evaluate(output_frame) if decision == :delay @notification_gate.enqueue(output_frame) return { delivered: false, reason: :delayed, pending: @notification_gate.pending_count } end end frame = render(output_frame) channel_registry.deliver(frame) end |
#route_to(output_frame, channel_id:) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/legion/gaia/output_router.rb', line 34 def route_to(output_frame, channel_id:) adapted = OutputFrame.new( content: output_frame.content, channel_id: channel_id, id: output_frame.id, in_reply_to: output_frame.in_reply_to, content_type: output_frame.content_type, session_continuity_id: output_frame.session_continuity_id, channel_hints: output_frame.channel_hints, metadata: output_frame., created_at: output_frame.created_at ) route(adapted) end |