class RabbitFeed::EventRouting::Application

Attributes

catch_all_event[R]
name[R]
named_events[R]

Public Class Methods

new(name) click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 38
def initialize(name)
  @name         = name
  @named_events = {}

  validate!
end

Public Instance Methods

accepted_routes() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 64
def handles_event?(event)
  (find_event event).present?
end

Private Instance Methods

accept_any_event(&block) click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 80
def accept_any_event(&block)
  raise ConfigurationError, "Routing has already been defined for the event catch-all: :any in application: #{name}" if catch_all_event.present?
  event = (Event.new '*', block)
  @catch_all_event = event
end
accept_named_event(name, &block) click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 74
def accept_named_event(name, &block)
  raise ConfigurationError, "Routing has already been defined for the event with name: #{name} in application: #{self.name}" if named_events.key? name
  event = (Event.new name, block)
  named_events[event.name] = event
end
all_events() click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 90
def all_events
  events = named_events.values
  events << catch_all_event if catch_all_event.present?
  events
end
find_event(event) click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 86
def find_event(event)
  [named_events[event.name], catch_all_event].compact.first
end
validate!() click to toggle source
# File lib/rabbit_feed/event_routing.rb, line 70
def validate!
  raise ConfigurationError, "Bad application specification for #{name}: #{errors.messages}" if invalid?
end