Sha256: 5344a428250ad17cb06a0db4ff869227d2ab75b6ca87b910439ba96de08bc3e5
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# @api private module Wisper class ObjectRegistration < Registration attr_reader :with, :prefix, :allowed_classes, :broadcaster 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 def broadcast(event, publisher, *args, **kwargs) 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, **kwargs) end end private def publisher_in_scope?(publisher) allowed_classes.empty? || publisher.class.ancestors.any? { |ancestor| allowed_classes.include?(ancestor.to_s) } end def map_event_to_method(event) prefix + (with || event).to_s end 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 def configuration Wisper.configuration end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
wisper-3.0.0.rc1 | lib/wisper/registration/object.rb |
wisper-compat-4.0.0 | lib/wisper/registration/object.rb |