Class: Wampus::Topic
- Inherits:
-
Object
- Object
- Wampus::Topic
- Defined in:
- lib/wampus/topic.rb
Instance Attribute Summary collapse
-
#allow_partial_uri_match ⇒ Object
readonly
Returns the value of attribute allow_partial_uri_match.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#publish_handler ⇒ Object
Returns the value of attribute publish_handler.
-
#subscribe_handler ⇒ Object
Returns the value of attribute subscribe_handler.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #add_subscriber(connection) ⇒ Object
-
#initialize(uri, allow_partial_uri_match = false) ⇒ Topic
constructor
A new instance of Topic.
- #remove_subscriber(connection) ⇒ Object
- #subscribers(excluded = [], eligible = []) ⇒ Object
Constructor Details
#initialize(uri, allow_partial_uri_match = false) ⇒ Topic
Returns a new instance of Topic.
9 10 11 12 13 14 15 |
# File 'lib/wampus/topic.rb', line 9 def initialize(uri, allow_partial_uri_match = false) @uri = uri @allow_partial_uri_match = allow_partial_uri_match @connections = Set.new @subscribe_handler = [nil, nil, false] @publish_handler = [nil, nil, false] end |
Instance Attribute Details
#allow_partial_uri_match ⇒ Object (readonly)
Returns the value of attribute allow_partial_uri_match.
7 8 9 |
# File 'lib/wampus/topic.rb', line 7 def allow_partial_uri_match @allow_partial_uri_match end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
7 8 9 |
# File 'lib/wampus/topic.rb', line 7 def connections @connections end |
#publish_handler ⇒ Object
Returns the value of attribute publish_handler.
6 7 8 |
# File 'lib/wampus/topic.rb', line 6 def publish_handler @publish_handler end |
#subscribe_handler ⇒ Object
Returns the value of attribute subscribe_handler.
6 7 8 |
# File 'lib/wampus/topic.rb', line 6 def subscribe_handler @subscribe_handler end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/wampus/topic.rb', line 7 def uri @uri end |
Instance Method Details
#add_subscriber(connection) ⇒ Object
17 18 19 20 |
# File 'lib/wampus/topic.rb', line 17 def add_subscriber(connection) @connections << connection connection.subscribe_to_topic self end |
#remove_subscriber(connection) ⇒ Object
22 23 24 25 |
# File 'lib/wampus/topic.rb', line 22 def remove_subscriber(connection) @connections.delete connection connection.unsubscribe_from_topic self end |
#subscribers(excluded = [], eligible = []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wampus/topic.rb', line 27 def subscribers(excluded = [], eligible = []) connections = @connections.to_a if !!excluded == false excluded = [] end if !!eligible == false eligible = [] end connections.delete_if { |connection| excluded.include? connection.id } unless excluded.empty? connections.keep_if { |connection| eligible.include? connection.id } unless eligible.empty? connections end |