Sha256: f1dafd24753cb49741b3a3948fc1d79138194933db9a64ece82c82de83406d3f
Contents?: true
Size: 1.22 KB
Versions: 18
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module AnyCable module Rails module Connections 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) return unless @cached_ids @cached_ids[name] ||= @cached_ids.fetch(name) do AnyCable::Rails.deserialize(@serialized_ids[name.to_s]) end end end end end end
Version data entries
18 entries across 18 versions & 2 rubygems