Module: Foobara::DetachedEntity::Concerns::PrimaryKey::ClassMethods

Defined in:
foobara-0.0.110/projects/detached_entity/src/concerns/primary_key.rb

Instance Method Summary collapse

Instance Method Details

#foobara_primary_key_attributeObject Also known as: primary_key_attribute



28
29
30
31
32
33
34
# File 'foobara-0.0.110/projects/detached_entity/src/concerns/primary_key.rb', line 28

def foobara_primary_key_attribute
  return @foobara_primary_key_attribute if @foobara_primary_key_attribute

  if superclass != DetachedEntity && superclass.respond_to?(:foobara_primary_key_attribute)
    @foobara_primary_key_attribute = superclass.foobara_primary_key_attribute
  end
end

#primary_key(attribute_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'foobara-0.0.110/projects/detached_entity/src/concerns/primary_key.rb', line 10

def primary_key(attribute_name)
  if primary_key_attribute
    # :nocov:
    raise "Primary key already set to #{primary_key_attribute}"
    # :nocov:
  end

  if attribute_name.nil? || attribute_name.empty?
    # :nocov:
    raise ArgumentError, "Primary key can't be blank"
    # :nocov:
  end

  @foobara_primary_key_attribute = attribute_name.to_sym

  set_model_type
end