Sha256: 4cf6054e51d8df1481c21c0b96c9bb76083ca2dc5415be6cbbe4d228fa9fd70b
Contents?: true
Size: 1.09 KB
Versions: 22
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true module ActionCable module Connection module SerializableIdentification extend ActiveSupport::Concern class_methods do def identified_by(*identifiers) super Array(identifiers).each do |identifier| define_method(identifier) do instance_variable_get(:"@#{identifier}") || fetch_identifier(identifier) end end end end # Generate identifiers info. # Converts GlobalID compatible vars to corresponding global IDs params. def identifiers_hash identifiers.each_with_object({}) do |id, acc| obj = instance_variable_get("@#{id}") next unless obj acc[id] = AnyCable::Rails.serialize(obj) end.compact end def identifiers_json identifiers_hash.to_json end # Fetch identifier and deserialize if neccessary def fetch_identifier(name) @cached_ids[name] ||= @cached_ids.fetch(name) do AnyCable::Rails.deserialize(ids[name.to_s]) end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems