Module: Skinny::Helpers

Defined in:
lib/skinny.rb

Instance Method Summary collapse

Instance Method Details

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



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

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



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

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

#websocket?Boolean

Returns:

  • (Boolean)


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

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