Class: ActiveRecord::Key
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Inherits: | Object |
| Defined in: | activerecord/lib/active_record/key.rb |
Class Method Summary
Instance Attribute Summary
- #columns readonly
- #composite? ⇒ Boolean readonly
- #each readonly
- #index_with readonly
- #name readonly
- #present? ⇒ Boolean readonly
Instance Method Summary
- #==(other) (also: #eql?)
- #[](index)
-
#_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.
- #all? ⇒ Boolean
- #any? ⇒ Boolean
- #arel_columns(table)
- #cast(values, model)
- #count
- #each_with_index
-
#eql?(other)
Alias for #==.
- #expects_multiple_ids?(value) ⇒ Boolean
- #hash
- #include?(column) ⇒ Boolean
- #inferred_id
- #inferred_key
- #length (also: #size)
- #map
-
#map_value
Yields column names and returns a scalar or tuple according to the key's shape.
- #none? ⇒ Boolean
-
#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. -
#size
Alias for #length.
-
#subset?(other) ⇒ Boolean
Returns true if every column of this key is also a column of
other. - #to_a
- #to_s
-
#value_of(record, normalizers = nil)
Reads attributes with optional per-column normalizers.
- #where_clauses(values)
- #where_hash(values)
Class Method Details
.for(name)
[ GitHub ]Instance Attribute Details
#columns (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 18
attr_reader :name, :columns
#composite? ⇒ Boolean (readonly)
# 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 ]#[](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.
# File 'activerecord/lib/active_record/key.rb', line 90
def _value_of(record, normalizers = nil) raise NotImplementedError end
#all? ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 26
def all?(...) = @columns.all?(...)
#any? ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 27
def any?(...) = @columns.any?(...)
#arel_columns(table)
# File 'activerecord/lib/active_record/key.rb', line 67
def arel_columns(table) raise NotImplementedError end
#cast(values, model)
# 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 #==.
# File 'activerecord/lib/active_record/key.rb', line 53
alias_method :eql?, :==
#expects_multiple_ids?(value) ⇒ Boolean
# 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
# File 'activerecord/lib/active_record/key.rb', line 110
def include?(column) raise NotImplementedError end
#inferred_id
# File 'activerecord/lib/active_record/key.rb', line 98
def inferred_id raise NotImplementedError end
#inferred_key
# 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.
# File 'activerecord/lib/active_record/key.rb', line 77
def map_value raise NotImplementedError end
#none? ⇒ Boolean
# 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.
# File 'activerecord/lib/active_record/key.rb', line 121
def resolve_aliases(owner) raise NotImplementedError end
#size
Alias for #length.
# 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.
# 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.
# File 'activerecord/lib/active_record/key.rb', line 84
def value_of(record, normalizers = nil) raise NotImplementedError end
#where_clauses(values)
# File 'activerecord/lib/active_record/key.rb', line 106
def where_clauses(values) raise NotImplementedError end
#where_hash(values)
# File 'activerecord/lib/active_record/key.rb', line 63
def where_hash(values) raise NotImplementedError end