Module: Fargo::Publisher
- Included in:
- Client, Connection::Base, Server
- Defined in:
- lib/fargo/publisher.rb
Instance Attribute Summary collapse
-
#subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Instance Method Summary collapse
- #publish(message_type, hash = {}) ⇒ Object
- #subscribe(&subscriber) ⇒ Object
- #subscribed_to? ⇒ Boolean
- #unsubscribe(&subscriber) ⇒ Object
Instance Attribute Details
#subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
4 5 6 |
# File 'lib/fargo/publisher.rb', line 4 def subscribers @subscribers end |
Instance Method Details
#publish(message_type, hash = {}) ⇒ Object
22 23 24 |
# File 'lib/fargo/publisher.rb', line 22 def publish , hash = {} @subscribers.each { |subscriber| subscriber.call , hash } if @subscribers end |
#subscribe(&subscriber) ⇒ Object
6 7 8 9 10 |
# File 'lib/fargo/publisher.rb', line 6 def subscribe &subscriber raise RuntimeError.new("Need a subscription block!") if subscriber.nil? Fargo.logger.debug "#{self}: subscribing #{subscriber}" (@subscribers ||= []) << subscriber end |
#subscribed_to? ⇒ Boolean
12 13 14 |
# File 'lib/fargo/publisher.rb', line 12 def subscribed_to? @subscribers && @subscribers.size > 0 end |
#unsubscribe(&subscriber) ⇒ Object
16 17 18 19 20 |
# File 'lib/fargo/publisher.rb', line 16 def unsubscribe &subscriber raise RuntimeError.new("Need a subscription block!") if subscriber.nil? Fargo.logger.debug "#{self}: unsubscribing #{subscriber}" (@subscribers ||= []).delete subscriber end |