Module: NoBrainer::Document::PrimaryKey

Extended by:
ActiveSupport::Concern, Autoload
Includes:
ActiveModel::Conversion
Defined in:
lib/no_brainer/document/primary_key.rb

Defined Under Namespace

Modules: ClassMethods, Generator

Constant Summary collapse

DEFAULT_PK_NAME =
:id

Instance Method Summary collapse

Methods included from Autoload

autoload, autoload_and_include, eager_autoload, eager_load!, extended

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



18
19
20
21
22
# File 'lib/no_brainer/document/primary_key.rb', line 18

def ==(other)
  return super unless self.class == other.class
  return self.equal?(other) if in_atomic?
  !pk_value.nil? && pk_value == other.pk_value
end

#cache_keyObject



27
28
29
# File 'lib/no_brainer/document/primary_key.rb', line 27

def cache_key
  "#{self.class.table_name}/#{pk_value}"
end

#pk_valueObject



10
11
12
# File 'lib/no_brainer/document/primary_key.rb', line 10

def pk_value
  __send__(self.class.pk_name)
end

#pk_value=(value) ⇒ Object



14
15
16
# File 'lib/no_brainer/document/primary_key.rb', line 14

def pk_value=(value)
  __send__("#{self.class.pk_name}=", value)
end

#to_keyObject



31
32
33
34
# File 'lib/no_brainer/document/primary_key.rb', line 31

def to_key
  # ActiveModel::Conversion
  [pk_value]
end