Class: Wampus::Connection
- Inherits:
-
Object
- Object
- Wampus::Connection
- Defined in:
- lib/wampus/connection.rb
Instance Attribute Summary collapse
-
#auth_timeout_call ⇒ Object
Returns the value of attribute auth_timeout_call.
-
#authenticated ⇒ Object
Returns the value of attribute authenticated.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pending_auth ⇒ Object
Returns the value of attribute pending_auth.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
-
#topics ⇒ Object
readonly
Returns the value of attribute topics.
-
#websocket ⇒ Object
readonly
Returns the value of attribute websocket.
Instance Method Summary collapse
- #add_prefix(prefix, uri) ⇒ Object
- #close_connection ⇒ Object
-
#initialize(id, websocket) ⇒ Connection
constructor
A new instance of Connection.
- #resolve_prefix(uri) ⇒ Object
-
#shrink_prefix(uri) ⇒ Object
TODO Use.
- #subscribe_to_topic(topic) ⇒ Object
- #unsubscribe_from_topic(topic) ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(id, websocket) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wampus/connection.rb', line 8 def initialize(id, websocket) @id = id @websocket = websocket @prefixes = {} @topics = [] @authenticated = false @pending_auth = nil @auth_timeout_call = nil end |
Instance Attribute Details
#auth_timeout_call ⇒ Object
Returns the value of attribute auth_timeout_call.
6 7 8 |
# File 'lib/wampus/connection.rb', line 6 def auth_timeout_call @auth_timeout_call end |
#authenticated ⇒ Object
Returns the value of attribute authenticated.
6 7 8 |
# File 'lib/wampus/connection.rb', line 6 def authenticated @authenticated end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/wampus/connection.rb', line 4 def id @id end |
#pending_auth ⇒ Object
Returns the value of attribute pending_auth.
6 7 8 |
# File 'lib/wampus/connection.rb', line 6 def pending_auth @pending_auth end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
4 5 6 |
# File 'lib/wampus/connection.rb', line 4 def prefixes @prefixes end |
#topics ⇒ Object (readonly)
Returns the value of attribute topics.
4 5 6 |
# File 'lib/wampus/connection.rb', line 4 def topics @topics end |
#websocket ⇒ Object (readonly)
Returns the value of attribute websocket.
4 5 6 |
# File 'lib/wampus/connection.rb', line 4 def websocket @websocket end |
Instance Method Details
#add_prefix(prefix, uri) ⇒ Object
37 38 39 |
# File 'lib/wampus/connection.rb', line 37 def add_prefix(prefix, uri) @prefixes[prefix] = uri end |
#close_connection ⇒ Object
31 32 33 34 35 |
# File 'lib/wampus/connection.rb', line 31 def close_connection @topics.each do |topic| topic.remove_subscriber self end end |
#resolve_prefix(uri) ⇒ Object
41 42 43 44 |
# File 'lib/wampus/connection.rb', line 41 def resolve_prefix(uri) prefix = @prefixes.keys.select{|p| uri.include? p}.sort(&:length).last prefix ? @prefixes[prefix] + uri[/(?<=:)(.+)/].to_s : uri end |
#shrink_prefix(uri) ⇒ Object
TODO Use
47 48 49 |
# File 'lib/wampus/connection.rb', line 47 def shrink_prefix(uri) # TODO Implement end |
#subscribe_to_topic(topic) ⇒ Object
23 24 25 |
# File 'lib/wampus/connection.rb', line 23 def subscribe_to_topic(topic) @topics << topic end |
#unsubscribe_from_topic(topic) ⇒ Object
27 28 29 |
# File 'lib/wampus/connection.rb', line 27 def unsubscribe_from_topic(topic) @topics.delete topic end |
#write(msg) ⇒ Object
19 20 21 |
# File 'lib/wampus/connection.rb', line 19 def write(msg) @websocket.send msg end |