Class: ActionCable::Connection::Base
- Inherits:
-
Object
- Object
- ActionCable::Connection::Base
- Defined in:
- lib/anycable/actioncable/connection.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#transmissions ⇒ Object
readonly
Returns the value of attribute transmissions.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #dispose ⇒ Object
-
#fetch_identifier(name) ⇒ Object
Fetch identifier and deserialize if neccessary.
- #handle_close ⇒ Object
- #handle_open ⇒ Object
-
#identifiers_hash ⇒ Object
Generate identifiers info.
-
#initialize(env: {}, identifiers_json: '{}') ⇒ Base
constructor
A new instance of Base.
- #logger ⇒ Object
- #transmit(cable_message) ⇒ Object
Constructor Details
#initialize(env: {}, identifiers_json: '{}') ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 14 15 16 17 |
# File 'lib/anycable/actioncable/connection.rb', line 9 def initialize(env: {}, identifiers_json: '{}') @ids = ActiveSupport::JSON.decode(identifiers_json) @cached_ids = {} @env = env @coder = ActiveSupport::JSON @closed = false @transmissions = [] @subscriptions = ActionCable::Connection::Subscriptions.new(self) end |
Instance Attribute Details
#transmissions ⇒ Object (readonly)
Returns the value of attribute transmissions.
7 8 9 |
# File 'lib/anycable/actioncable/connection.rb', line 7 def transmissions @transmissions end |
Instance Method Details
#close ⇒ Object
31 32 33 |
# File 'lib/anycable/actioncable/connection.rb', line 31 def close @closed = true end |
#closed? ⇒ Boolean
35 36 37 |
# File 'lib/anycable/actioncable/connection.rb', line 35 def closed? @closed end |
#dispose ⇒ Object
43 44 45 46 |
# File 'lib/anycable/actioncable/connection.rb', line 43 def dispose @closed = false transmissions.clear end |
#fetch_identifier(name) ⇒ Object
Fetch identifier and deserialize if neccessary
59 60 61 62 63 64 65 |
# File 'lib/anycable/actioncable/connection.rb', line 59 def fetch_identifier(name) @cached_ids[name] ||= @cached_ids.fetch(name) do val = @ids[name.to_s] next val unless val.is_a?(String) GlobalID::Locator.locate(val) || val end end |
#handle_close ⇒ Object
26 27 28 29 |
# File 'lib/anycable/actioncable/connection.rb', line 26 def handle_close # subscriptions.unsubscribe_from_all disconnect if respond_to?(:disconnect) end |
#handle_open ⇒ Object
19 20 21 22 23 24 |
# File 'lib/anycable/actioncable/connection.rb', line 19 def handle_open connect if respond_to?(:connect) rescue ActionCable::Connection::Authorization::UnauthorizedError close end |
#identifiers_hash ⇒ Object
Generate identifiers info. Converts GlobalID compatible vars to corresponding global IDs params.
50 51 52 53 54 55 56 |
# File 'lib/anycable/actioncable/connection.rb', line 50 def identifiers_hash identifiers.each_with_object({}) do |id, acc| obj = instance_variable_get("@#{id}") next unless obj acc[id] = obj.try(:to_gid_param) || obj end end |
#logger ⇒ Object
67 68 69 |
# File 'lib/anycable/actioncable/connection.rb', line 67 def logger ::Rails.logger end |
#transmit(cable_message) ⇒ Object
39 40 41 |
# File 'lib/anycable/actioncable/connection.rb', line 39 def transmit() transmissions << encode() end |