Sha256: 2dc745524f4e57f821423f1b3adc90576857f4e66a092c9031580f46fe8e83e0

Contents?: true

Size: 765 Bytes

Versions: 1

Compression:

Stored size: 765 Bytes

Contents

begin
  require 'celluloid/autostart'
rescue LoadError
  # no-op
end

module Wisper
  class ObjectRegistration < Registration
    attr_reader :with, :async

    def initialize(listener, options)
      super(listener, options)
      @with  = options[:with]
      @async = options.fetch(:async, false)
    end

    def broadcast(event, *args)
      method_to_call = map_event_to_method(event)
      if should_broadcast?(event) && listener.respond_to?(method_to_call)
        unless async
          listener.public_send(method_to_call, *args)
        else
          AsyncListener.new(listener, method_to_call).async.public_send(method_to_call, *args)
        end
      end
    end

    private

    def map_event_to_method(event)
      with || event
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wisper-1.0.1 lib/wisper/registration/object.rb