Module: LiteCable::Connection::Identification::ClassMethods

Defined in:
lib/lite_cable/connection/identification.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance 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.



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

def identified_by(*identifiers)
  Array(identifiers).each do |identifier|
    attr_writer identifier
    define_method(identifier) do
      return instance_variable_get(:"@#{identifier}") if
        instance_variable_defined?(:"@#{identifier}")

      fetch_identifier(identifier.to_s)
    end
  end

  self.identifiers += identifiers
end