Class: WebSocketRb::Routes
- Inherits:
-
Object
- Object
- WebSocketRb::Routes
- Defined in:
- lib/web_socket_rb/routes.rb
Instance Attribute Summary collapse
-
#close_connection_code ⇒ Object
readonly
Returns the value of attribute close_connection_code.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#init_connection_code ⇒ Object
readonly
Returns the value of attribute init_connection_code.
-
#subscribes ⇒ Object
readonly
Returns the value of attribute subscribes.
Instance Method Summary collapse
-
#close_connection(&block) ⇒ Object
Execute this block of code when connection is closed.
-
#init_connection(&block) ⇒ Object
Execute block of code while initiation new connection.
-
#initialize ⇒ Routes
constructor
A new instance of Routes.
-
#subscribe(name, &block) ⇒ Object
Define method to subscribe incoming messages.
Constructor Details
#initialize ⇒ Routes
Returns a new instance of Routes.
6 7 8 9 |
# File 'lib/web_socket_rb/routes.rb', line 6 def initialize @subscribes = Hash.new([]) @config = OpenStruct.new(port: '9292') end |
Instance Attribute Details
#close_connection_code ⇒ Object (readonly)
Returns the value of attribute close_connection_code.
4 5 6 |
# File 'lib/web_socket_rb/routes.rb', line 4 def close_connection_code @close_connection_code end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/web_socket_rb/routes.rb', line 4 def config @config end |
#init_connection_code ⇒ Object (readonly)
Returns the value of attribute init_connection_code.
4 5 6 |
# File 'lib/web_socket_rb/routes.rb', line 4 def init_connection_code @init_connection_code end |
#subscribes ⇒ Object (readonly)
Returns the value of attribute subscribes.
4 5 6 |
# File 'lib/web_socket_rb/routes.rb', line 4 def subscribes @subscribes end |
Instance Method Details
#close_connection(&block) ⇒ Object
Execute this block of code when connection is closed
23 24 25 |
# File 'lib/web_socket_rb/routes.rb', line 23 def close_connection(&block) @close_connection_code = block end |
#init_connection(&block) ⇒ Object
Execute block of code while initiation new connection
18 19 20 |
# File 'lib/web_socket_rb/routes.rb', line 18 def init_connection(&block) @init_connection_code = block end |
#subscribe(name, &block) ⇒ Object
Define method to subscribe incoming messages
12 13 14 15 |
# File 'lib/web_socket_rb/routes.rb', line 12 def subscribe(name, &block) raise ArgumentError, 'Invalid name' unless name.is_a?(String) @subscribes[name] = block end |