Class: Wisper::ObjectRegistration

Inherits:
Registration show all
Defined in:
lib/wisper/registration/object.rb

Instance Attribute Summary collapse

Attributes inherited from Registration

#listener, #on

Instance Method Summary collapse

Constructor Details

#initialize(listener, options) ⇒ ObjectRegistration

Returns a new instance of ObjectRegistration.



5
6
7
8
9
10
11
# File 'lib/wisper/registration/object.rb', line 5

def initialize(listener, options)
  super(listener, options)
  @with   = options[:with]
  @prefix = stringify_prefix(options[:prefix])
  @allowed_classes = Array(options[:scope]).map(&:to_s).to_set
  @broadcaster = map_broadcaster(options[:async] || options[:broadcaster])
end

Instance Attribute Details

#allowed_classesObject (readonly)

Returns the value of attribute allowed_classes.



3
4
5
# File 'lib/wisper/registration/object.rb', line 3

def allowed_classes
  @allowed_classes
end

#broadcasterObject (readonly)

Returns the value of attribute broadcaster.



3
4
5
# File 'lib/wisper/registration/object.rb', line 3

def broadcaster
  @broadcaster
end

#prefixObject (readonly)

Returns the value of attribute prefix.



3
4
5
# File 'lib/wisper/registration/object.rb', line 3

def prefix
  @prefix
end

#withObject (readonly)

Returns the value of attribute with.



3
4
5
# File 'lib/wisper/registration/object.rb', line 3

def with
  @with
end

Instance Method Details

#broadcast(event, publisher, *args) ⇒ Object



13
14
15
16
17
18
# File 'lib/wisper/registration/object.rb', line 13

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