Class: ActiveRecord::Key::Single
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Key
|
|
|
Instance Chain:
self,
Key
|
|
| Inherits: |
Key
|
| Defined in: | activerecord/lib/active_record/key.rb |
Class Method Summary
- .new(name) ⇒ Single constructor
Instance Attribute Summary
- #composite? ⇒ Boolean readonly
Instance Method Summary
- #_value_of(record, normalizers = nil)
- #all?(pattern = (no_pattern = true)) ⇒ Boolean
- #any?(pattern = (no_pattern = true)) ⇒ Boolean
- #arel_columns(table)
- #cast(value, model)
- #each {|@name| ... }
- #each_with_index {|@name, 0| ... }
- #expects_multiple_ids?(value) ⇒ Boolean
- #include?(column) ⇒ Boolean
-
#inferred_id
Only composite keys have a single id to infer.
- #inferred_key
- #map
- #map_value {|@name| ... }
- #none?(pattern = (no_pattern = true)) ⇒ Boolean
- #resolve_aliases(owner)
- #subset?(other) ⇒ Boolean
- #value_of(record, normalizers = nil)
- #where_clauses(values)
- #where_hash(values)
- #zip(other) {|@name, | ... }
Constructor Details
.new(name) ⇒ Single
Instance Attribute Details
#composite? ⇒ Boolean (readonly)
[ GitHub ]
# File 'activerecord/lib/active_record/key.rb', line 172
def composite? false end
Instance Method Details
#_value_of(record, normalizers = nil)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 199
def _value_of(record, normalizers = nil) value = record._read_attribute(@name) normalizer = normalizers&.first normalizer ? normalizer.call(value) : value end
#all?(pattern = (no_pattern = true)) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 137
def all?(pattern = (no_pattern = true)) return super(pattern) unless no_pattern return super() unless block_given? yield(@name) ? true : false end
#any?(pattern = (no_pattern = true)) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 143
def any?(pattern = (no_pattern = true)) return super(pattern) unless no_pattern return super() unless block_given? yield(@name) ? true : false end
#arel_columns(table)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 180
def arel_columns(table) table[@name] end
#cast(value, model)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 184
def cast(value, model) model.type_for_attribute(@name).cast(value) end
#each {|@name| ... }
# File 'activerecord/lib/active_record/key.rb', line 131
def each return super unless block_given? yield @name self end
#each_with_index {|@name, 0| ... }
# File 'activerecord/lib/active_record/key.rb', line 155
def each_with_index return super unless block_given? yield @name, 0 @columns end
#expects_multiple_ids?(value) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 205
def expects_multiple_ids?(value) value.is_a?(Array) end
#include?(column) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 222
def include?(column) @name == column end
#inferred_id
Only composite keys have a single id to infer.
# File 'activerecord/lib/active_record/key.rb', line 210
def inferred_id nil end
#inferred_key
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 214
def inferred_key nil end
#map
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 161
def map return super unless block_given? [yield(@name)] end
#map_value {|@name| ... }
# File 'activerecord/lib/active_record/key.rb', line 188
def map_value return enum_for(:map_value) unless block_given? yield @name end
#none?(pattern = (no_pattern = true)) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 149
def none?(pattern = (no_pattern = true)) return super(pattern) unless no_pattern return super() unless block_given? yield(@name) ? false : true end
#resolve_aliases(owner)
[ GitHub ]
#subset?(other) ⇒ Boolean
# File 'activerecord/lib/active_record/key.rb', line 226
def subset?(other) other.include?(@name) end
#value_of(record, normalizers = nil)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 193
def value_of(record, normalizers = nil) value = record.read_attr(@name) normalizer = normalizers&.first normalizer ? normalizer.call(value) : value end
#where_clauses(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 218
def where_clauses(values) [where_hash(values)] end
#where_hash(values)
[ GitHub ]# File 'activerecord/lib/active_record/key.rb', line 176
def where_hash(values) { @name => values } end
#zip(other) {|@name, | ... }
# File 'activerecord/lib/active_record/key.rb', line 166
def zip(other) return [[@name, other[0]]] unless block_given? yield @name, other[0] nil end