Class: Wisper::ObjectRegistration

Inherits:
Object
  • Object
show all
Defined in:
lib/fragmentary/publisher.rb

Instance Method Summary collapse

Instance Method Details

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

For the registration to broadcast a specified event we require:

- 'should_broadcast?'    - If the listener susbcribed with an ':on' option, ensure that the event
                           is included in the 'on' list.
- 'listener.respond_to?' - The listener contains a handler for the event
- 'publisher_in_scope'   - If the listener subscribed with a ':scope' option, ensure that the
                           publisher's class is included in the 'scope' list.


71
72
73
74
75
76
# File 'lib/fragmentary/publisher.rb', line 71

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