Module: ActiveRecord::AttributeMethods

Defined in:
lib/composite_primary_keys/attribute_methods.rb,
lib/composite_primary_keys/attribute_methods/read.rb,
lib/composite_primary_keys/attribute_methods/write.rb,
lib/composite_primary_keys/attribute_methods/primary_key.rb

Defined Under Namespace

Modules: PrimaryKey, Read, Write

Instance Method Summary collapse

Instance Method Details

#_has_attribute?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/composite_primary_keys/attribute_methods.rb', line 15

def _has_attribute?(attr_name)
  # CPK
  # @attributes.key?(attr_name)
  Array(attr_name).all? { |attr| @attributes.key?(attr) }
end

#has_attribute?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/composite_primary_keys/attribute_methods.rb', line 3

def has_attribute?(attr_name)
  # CPK
  # attr_name = attr_name.to_s
  # attr_name = self.class.attribute_aliases[attr_name] || attr_name
  # @attributes.key?(attr_name)
  Array(attr_name).all? do |attr|
    attr = attr.to_s
    attr = self.class.attribute_aliases[attr] || attr
    @attributes.key?(attr)
  end
end