123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Key

Do not use. This class is for internal use only.
Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: activerecord/lib/active_record/key.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.for(name)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 5

def self.for(name)
  key = case name
  when Array
    Composite.new(name)
  when nil, false
    None.new
  else
    Single.new(name)
  end

  key.freeze
end

Instance Attribute Details

#columns (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 18

attr_reader :name, :columns

#composite? ⇒ Boolean (readonly)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 59

def composite?
  raise NotImplementedError
end

#each (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 24

delegate :each, :index_with, to: :@columns

#index_with (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 24

delegate :each, :index_with, to: :@columns

#name (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 18

attr_reader :name, :columns

#present? ⇒ Boolean (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 20

def present?
  true
end

Instance Method Details

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

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 50

def ==(other)
  other.is_a?(Key) && name == other.name
end

#[](index)

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 38

def [](index)
  @columns[index]
end

#_value_of(record, normalizers = nil)

Like #value_of, but columns must already be physical attribute names for the record's class; aliases are not resolved again.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 90

def _value_of(record, normalizers = nil)
  raise NotImplementedError
end

#all? ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 26

def all?(...) = @columns.all?(...)

#any? ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 27

def any?(...) = @columns.any?(...)

#arel_columns(table)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 67

def arel_columns(table)
  raise NotImplementedError
end

#cast(values, model)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 71

def cast(values, model)
  raise NotImplementedError
end

#count

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 29

def count(...) = @columns.count(...)

#each_with_index

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 31

def each_with_index(&) = @columns.each_with_index(&)

#eql?(other)

Alias for #==.

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 53

alias_method :eql?, :==

#expects_multiple_ids?(value) ⇒ Boolean

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 94

def expects_multiple_ids?(value)
  raise NotImplementedError
end

#hash

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 55

def hash
  name.hash
end

#include?(column) ⇒ Boolean

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 110

def include?(column)
  raise NotImplementedError
end

#inferred_id

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 98

def inferred_id
  raise NotImplementedError
end

#inferred_key

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 102

def inferred_key
  raise NotImplementedError
end

#length Also known as: #size

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 33

def length
  @columns.length
end

#map

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 30

def map(&) = @columns.map(&)

#map_value

Yields column names and returns a scalar or tuple according to the key's shape. Unlike Enumerable#map, a scalar result is not wrapped in an ::Array.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 77

def map_value
  raise NotImplementedError
end

#none? ⇒ Boolean

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 28

def none?(...) = @columns.none?(...)

#resolve_aliases(owner)

Returns this key with each column resolved through the aliases of owner, a model or record, or self when no column is aliased.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 121

def resolve_aliases(owner)
  raise NotImplementedError
end

#size

Alias for #length.

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 36

alias_method :size, :length

#subset?(other) ⇒ Boolean

Returns true if every column of this key is also a column of other.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 115

def subset?(other)
  raise NotImplementedError
end

#to_a

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 42

def to_a
  @columns
end

#to_s

[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 46

def to_s
  @name.to_s
end

#value_of(record, normalizers = nil)

Reads attributes with optional per-column normalizers. A nil list or entry leaves the corresponding values unchanged. Columns are declared names, resolved through the record's attribute aliases.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 84

def value_of(record, normalizers = nil)
  raise NotImplementedError
end

#where_clauses(values)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 106

def where_clauses(values)
  raise NotImplementedError
end

#where_hash(values)

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activerecord/lib/active_record/key.rb', line 63

def where_hash(values)
  raise NotImplementedError
end