class ActiveDomain::ProjectionRegistry
Attributes
handlers[RW]
Public Class Methods
invoke(event)
click to toggle source
# File lib/active_domain/projection_registry.rb, line 14 def self.invoke(event) instance.invoke event end
new()
click to toggle source
# File lib/active_domain/projection_registry.rb, line 31 def initialize self.handlers = Hash.new do |hash, key| hash[key] = [] end self.class.registry.freeze.each do |handler| handler.public_instance_methods(false).each do |method_name| method = handler.instance_method method_name event_type = (method_name.to_s.split('__') * '/').camelcase fail TooManyArgumentsError if 1 != method.arity handlers[event_type] << method end end handlers.freeze end
register(event_handler)
click to toggle source
# File lib/active_domain/projection_registry.rb, line 10 def self.register(event_handler) registry << event_handler end
Public Instance Methods
invoke(event)
click to toggle source
# File lib/active_domain/projection_registry.rb, line 18 def invoke(event) event_type = event.class.name.to_s return unless handlers.key? event_type handlers[event_type].each do |handler_method| handler_method.owner.new.send handler_method.name, event end end