Class: Rack::WebSocket::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/websocket/application.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Application

Initializer



18
19
20
# File 'lib/rack/websocket/application.rb', line 18

def initialize(options = {})
  @options = DEFAULT_OPTIONS.merge(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Forward all missing methods to handler



34
35
36
37
38
39
40
# File 'lib/rack/websocket/application.rb', line 34

def method_missing(sym, *args, &block)
  if websocket_handler && websocket_handler.respond_to?(sym)
    websocket_handler.send sym, *args, &block
  else
    super
  end
end

Class Attribute Details

.websocket_handlerObject

Returns the value of attribute websocket_handler.



8
9
10
# File 'lib/rack/websocket/application.rb', line 8

def websocket_handler
  @websocket_handler
end

Instance Method Details

#_call(env) ⇒ Object

Forward call to duplicated handler



29
30
31
# File 'lib/rack/websocket/application.rb', line 29

def _call(env)
  websocket_handler.call(env)
end

#call(env) ⇒ Object

Detect handler and duplicate it’s instance



23
24
25
26
# File 'lib/rack/websocket/application.rb', line 23

def call(env)
  detect_handler(env)
  dup._call(env)
end

#on_close(env) ⇒ Object



14
# File 'lib/rack/websocket/application.rb', line 14

def on_close(env); end

#on_error(env, error) ⇒ Object



15
# File 'lib/rack/websocket/application.rb', line 15

def on_error(env, error); end

#on_message(env, msg) ⇒ Object



13
# File 'lib/rack/websocket/application.rb', line 13

def on_message(env, msg); end

#on_open(env) ⇒ Object

Standard WebSocket calls



12
# File 'lib/rack/websocket/application.rb', line 12

def on_open(env); end