class Wisper::ObjectRegistration
Attributes
allowed_classes[R]
broadcaster[R]
prefix[R]
with[R]
Public Class Methods
new(listener, options)
click to toggle source
Calls superclass method
# File lib/wisper/registration/object.rb, line 7 def initialize(listener, options) super(listener, options) @with = options[:with] @prefix = ValueObjects::Prefix.new options[:prefix] @allowed_classes = Array(options[:scope]).map(&:to_s).to_set @broadcaster = map_broadcaster(options[:async] || options[:broadcaster]) end
Public Instance Methods
broadcast(event, publisher, *args)
click to toggle source
# File lib/wisper/registration/object.rb, line 15 def broadcast(event, publisher, *args) method_to_call = map_event_to_method(event) if should_broadcast?(event) && listener.respond_to?(method_to_call) && publisher_in_scope?(publisher) broadcaster.broadcast(listener, publisher, method_to_call, args) end end
Private Instance Methods
configuration()
click to toggle source
# File lib/wisper/registration/object.rb, line 39 def configuration Wisper.configuration end
map_broadcaster(value)
click to toggle source
# File lib/wisper/registration/object.rb, line 32 def map_broadcaster(value) return value if value.respond_to?(:broadcast) value = :async if value == true value = :default if value == nil configuration.broadcasters.fetch(value) end
map_event_to_method(event)
click to toggle source
# File lib/wisper/registration/object.rb, line 28 def map_event_to_method(event) prefix + (with || event).to_s end
publisher_in_scope?(publisher)
click to toggle source
# File lib/wisper/registration/object.rb, line 24 def publisher_in_scope?(publisher) allowed_classes.empty? || publisher.class.ancestors.any? { |ancestor| allowed_classes.include?(ancestor.to_s) } end