Class: WebSocketRb::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/web_socket_rb/routes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoutes

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_codeObject (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

#configObject (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_codeObject (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

#subscribesObject (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

Raises:

  • (ArgumentError)


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