Module: Skinny::Helpers

Defined in:
lib/skinny.rb

Instance Method Summary collapse

Instance Method Details

#websocket(options = {}, &block) ⇒ Object



438
439
440
441
442
443
444
# File 'lib/skinny.rb', line 438

def websocket options={}, &block
  env[SKINNY_WEBSOCKET] ||= begin
    raise RuntimerError, "Not a WebSocket request" unless websocket?
    options[:on_message] = block if block_given?
    Websocket.from_env(env, options)
  end
end

#websocket!(options = {}, &block) ⇒ Object



446
447
448
# File 'lib/skinny.rb', line 446

def websocket! options={}, &block
  websocket(options, &block).start!
end

#websocket?Boolean

Returns:

  • (Boolean)


434
435
436
# File 'lib/skinny.rb', line 434

def websocket?
  env[CONNECTION] =~ UPGRADE_REGEXP && env[UPGRADE] =~ WEBSOCKET_REGEXP
end