Module: AnyCable::Rails::Connections::SerializableIdentification
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/anycable/rails/connections/serializable_identification.rb
Defined Under Namespace
Modules: ConnectionGID
Instance Method Summary collapse
-
#fetch_identifier(name) ⇒ Object
Fetch identifier and deserialize if neccessary.
-
#identifiers_hash ⇒ Object
Generate identifiers info.
- #identifiers_json ⇒ Object
- #identifiers_json=(val) ⇒ Object
Instance Method Details
#fetch_identifier(name) ⇒ Object
Fetch identifier and deserialize if neccessary
55 56 57 58 59 60 61 |
# File 'lib/anycable/rails/connections/serializable_identification.rb', line 55 def fetch_identifier(name) return unless @cached_ids @cached_ids[name] ||= @cached_ids.fetch(name) do AnyCable::Serializer.deserialize(@serialized_ids[name.to_s]) end end |
#identifiers_hash ⇒ Object
Generate identifiers info. Converts GlobalID compatible vars to corresponding global IDs params.
36 37 38 39 40 41 42 43 |
# File 'lib/anycable/rails/connections/serializable_identification.rb', line 36 def identifiers_hash identifiers.each_with_object({}) do |id, acc| obj = instance_variable_get("@#{id}") next unless obj acc[id] = AnyCable::Serializer.serialize(obj) end.compact end |
#identifiers_json ⇒ Object
45 46 47 |
# File 'lib/anycable/rails/connections/serializable_identification.rb', line 45 def identifiers_json identifiers_hash.to_json end |
#identifiers_json=(val) ⇒ Object
49 50 51 52 |
# File 'lib/anycable/rails/connections/serializable_identification.rb', line 49 def identifiers_json=(val) @cached_ids = {} @serialized_ids = val ? ActiveSupport::JSON.decode(val) : {} end |