Class: RabbitFeed::EventRouting::Application
- Inherits:
-
Object
- Object
- RabbitFeed::EventRouting::Application
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/rabbit_feed/event_routing.rb
Instance Attribute Summary collapse
-
#catch_all_event ⇒ Object
readonly
Returns the value of attribute catch_all_event.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#named_events ⇒ Object
readonly
Returns the value of attribute named_events.
Instance Method Summary collapse
- #accepted_routes ⇒ Object
- #event(name, &block) ⇒ Object
- #handle_event(event) ⇒ Object
- #handles_event?(event) ⇒ Boolean
-
#initialize(name) ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize(name) ⇒ Application
Returns a new instance of Application.
38 39 40 41 42 43 |
# File 'lib/rabbit_feed/event_routing.rb', line 38 def initialize(name) @name = name @named_events = {} validate! end |
Instance Attribute Details
#catch_all_event ⇒ Object (readonly)
Returns the value of attribute catch_all_event.
35 36 37 |
# File 'lib/rabbit_feed/event_routing.rb', line 35 def catch_all_event @catch_all_event end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/rabbit_feed/event_routing.rb', line 35 def name @name end |
#named_events ⇒ Object (readonly)
Returns the value of attribute named_events.
35 36 37 |
# File 'lib/rabbit_feed/event_routing.rb', line 35 def named_events @named_events end |
Instance Method Details
#accepted_routes ⇒ Object
53 54 55 56 57 |
# File 'lib/rabbit_feed/event_routing.rb', line 53 def accepted_routes all_events.map do |event| "#{RabbitFeed.environment}#{RabbitFeed.configuration.route_prefix_extension}.#{name}.#{event.name}" end end |
#event(name, &block) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rabbit_feed/event_routing.rb', line 45 def event(name, &block) if name == :any accept_any_event(&block) else accept_named_event(name, &block) end end |
#handle_event(event) ⇒ Object
59 60 61 62 |
# File 'lib/rabbit_feed/event_routing.rb', line 59 def handle_event(event) event_rule = find_event event event_rule.handle_event event end |
#handles_event?(event) ⇒ Boolean
64 65 66 |
# File 'lib/rabbit_feed/event_routing.rb', line 64 def handles_event?(event) (find_event event).present? end |