Class: Rage::Cable::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/cable/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.identified_by(*identifiers) ⇒ Object

Mark a key as being a connection identifier index that can then be used to find the specific connection again later. Common identifiers are current_user and current_account, but could be anything.

Parameters:

  • identifiers (Symbol, Array<Symbol>)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rage/cable/connection.rb', line 11

def self.identified_by(*identifiers)
  identifiers.each do |method_name|
    define_method(method_name) do
      @__identified_by_map[method_name]
    end

    define_method("#{method_name}=") do |data|
      @__identified_by_map[method_name] = data
    end

    Rage::Cable::Channel.__prepare_id_method(method_name)
  end
end

Instance Method Details

#cookiesRage::Cookies

Get the cookie object. See Rage::Cookies.

Returns:



54
55
56
# File 'lib/rage/cable/connection.rb', line 54

def cookies
  @__cookies ||= Rage::Cookies.new(@__env, ReadOnlyHash.new)
end

#paramsHash{Symbol=>String,Array,Hash}

Get URL query parameters.

Returns:

  • (Hash{Symbol=>String,Array,Hash})


68
69
70
# File 'lib/rage/cable/connection.rb', line 68

def params
  @__params ||= Iodine::Rack::Utils.parse_nested_query(@__env["QUERY_STRING"])
end

#reject_unauthorized_connectionObject

Reject the WebSocket connection.



36
37
38
# File 'lib/rage/cable/connection.rb', line 36

def reject_unauthorized_connection
  @rejected = true
end

#rejected?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rage/cable/connection.rb', line 40

def rejected?
  !!@rejected
end

#requestRage::Request

Get the request object. See Request.

Returns:



47
48
49
# File 'lib/rage/cable/connection.rb', line 47

def request
  @__request ||= Rage::Request.new(@__env)
end

#sessionRage::Session

Get the session object. See Session.

Returns:



61
62
63
# File 'lib/rage/cable/connection.rb', line 61

def session
  @__session ||= Rage::Session.new(cookies)
end