Class: ActiveModel::ReindexedAttributeSet
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | activemodel/lib/active_model/attribute_set.rb |
Overview
This is an adapter specifically for people using becomes.
Class Method Summary
-
.new(shared, own) ⇒ ReindexedAttributeSet
constructor
: (ActiveModel::AttributeSet |
ReindexedAttributeSet,AttributeSet|ReindexedAttributeSet) -> void.
Instance Attribute Summary
-
#read_only? ⇒ Boolean
readonly
: () -> bool.
- #own readonly protected
-
#shared?(name) ⇒ Boolean
readonly
private
: (String) -> bool.
Instance Method Summary
-
#==(other)
: (untyped) -> bool.
-
#[](name)
: (String) ->
Attribute - #[]=(name, attribute)
-
#accessed
: () -> Array.
-
#cast_types
: () -> Hash[String, ActiveModel::Type::Value].
-
#deep_dup
: () ->
ReindexedAttributeSet -
#each_value(&block)
: () { (ActiveModel::Attribute) -> void } -> self : () -> Enumerator[ActiveModel::Attribute, self].
-
#fetch_value(name, &block)
: (String) ?{ (String) -> untyped } -> untyped.
-
#fetch_value!(name)
: (String) -> untyped.
-
#fetch_value_at(index, &block)
: (Integer) ?{ (String) -> untyped } -> untyped.
-
#fetch_value_at!(index)
: (Integer) -> untyped.
-
#freeze
: () -> self.
-
#include?(name)
Alias for #key?.
-
#indexes
: () -> (Hash[String, Integer] |
IndexedRow::ExtendedIndexes). -
#initialize_clone(_)
: (ActiveModel::ReindexedAttributeSet) -> void.
-
#initialize_dup(_)
: (ActiveModel::ReindexedAttributeSet) -> void.
-
#key?(name) ⇒ Boolean
(also: #include?)
: (String) -> bool.
-
#keys
: () -> Array.
-
#map(&block)
: () { (ActiveModel::Attribute) ->
Attribute} ->ReindexedAttributeSet -
#name_at(index)
: (Integer) -> String?
-
#reset(name)
: (String) ->
ActiveModel::Attribute? -
#to_h
Alias for #to_hash.
-
#to_hash
(also: #to_h)
: () -> Hash[String, untyped].
-
#values
: () -> Array.
-
#values_before_type_cast
: () -> Hash[String, untyped].
-
#values_for_database
: () -> Hash[String, untyped].
-
#write_cast_value(name, value)
: (String, untyped) ->
Attribute -
#write_from_database(name, value)
: (String, untyped) ->
Attribute -
#write_from_user(name, value)
: (String, untyped) -> untyped.
- #shared readonly protected
- #own_only(names) private
-
#set_for(name)
private
: (String) -> (ActiveModel::AttributeSet |
ReindexedAttributeSet). - #to_shared_indexes private
Constructor Details
.new(shared, own) ⇒ ReindexedAttributeSet
: (ActiveModel::AttributeSet | ReindexedAttributeSet, AttributeSet | ReindexedAttributeSet) -> void
# File 'activemodel/lib/active_model/attribute_set.rb', line 685
def initialize(shared, own) @shared = shared @own = own @to_shared = to_shared_indexes end
Instance Attribute Details
#own (readonly, protected)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 854
attr_reader :shared, :own
#read_only? ⇒ Boolean (readonly)
: () -> bool
# File 'activemodel/lib/active_model/attribute_set.rb', line 849
def read_only? false end
Instance Method Details
#==(other)
: (untyped) -> bool
#[](name)
: (String) -> Attribute
# File 'activemodel/lib/active_model/attribute_set.rb', line 697
def [](name) set_for(name)[name] end
#[]=(name, attribute)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 702
def []=(name, attribute) set_for(name)[name] = attribute end
#accessed
: () -> Array
# File 'activemodel/lib/active_model/attribute_set.rb', line 793
def accessed @shared.accessed | own_only(@own.accessed) end
#cast_types
: () -> Hash[String, ActiveModel::Type::Value]
# File 'activemodel/lib/active_model/attribute_set.rb', line 778
def cast_types @shared.cast_types.merge(own_only(@own.cast_types)) end
#deep_dup
: () -> ReindexedAttributeSet
# File 'activemodel/lib/active_model/attribute_set.rb', line 818
def deep_dup self.class.new(@shared.deep_dup, @own.deep_dup) end
#each_value(&block)
: () { (ActiveModel::Attribute) -> void } -> self : () -> Enumerator[ActiveModel::Attribute, self]
# File 'activemodel/lib/active_model/attribute_set.rb', line 799
def each_value(&block) return enum_for(:each_value) unless block @shared.each_value(&block) @own.each_value { |attribute| yield attribute unless shared?(attribute.name) } self end
#fetch_value(name, &block)
: (String) ?{ (String) -> untyped } -> untyped
# File 'activemodel/lib/active_model/attribute_set.rb', line 718
def fetch_value(name, &block) set_for(name).fetch_value(name, &block) end
#fetch_value!(name)
: (String) -> untyped
# File 'activemodel/lib/active_model/attribute_set.rb', line 723
def fetch_value!(name) set_for(name).fetch_value!(name) end
#fetch_value_at(index, &block)
: (Integer) ?{ (String) -> untyped } -> untyped
# File 'activemodel/lib/active_model/attribute_set.rb', line 728
def fetch_value_at(index, &block) if shared_index = @to_shared[index] @shared.fetch_value_at(shared_index, &block) else @own.fetch_value_at(index, &block) end end
#fetch_value_at!(index)
: (Integer) -> untyped
# File 'activemodel/lib/active_model/attribute_set.rb', line 737
def fetch_value_at!(index) if shared_index = @to_shared[index] @shared.fetch_value_at!(shared_index) else @own.fetch_value_at!(index) end end
#freeze
: () -> self
# File 'activemodel/lib/active_model/attribute_set.rb', line 837
def freeze @shared.freeze @own.freeze super end
#include?(name)
Alias for #key?.
# File 'activemodel/lib/active_model/attribute_set.rb', line 710
alias :include? :key?
#indexes
: () -> (Hash[String, Integer] | IndexedRow::ExtendedIndexes)
# File 'activemodel/lib/active_model/attribute_set.rb', line 692
def indexes @own.indexes end
#initialize_clone(_)
: (ActiveModel::ReindexedAttributeSet) -> void
# File 'activemodel/lib/active_model/attribute_set.rb', line 830
def initialize_clone(_) @shared = @shared.clone @own = @own.clone super end
#initialize_dup(_)
: (ActiveModel::ReindexedAttributeSet) -> void
# File 'activemodel/lib/active_model/attribute_set.rb', line 823
def initialize_dup(_) @shared = @shared.dup @own = @own.dup super end
#key?(name) ⇒ Boolean
Also known as: #include?
: (String) -> bool
# File 'activemodel/lib/active_model/attribute_set.rb', line 707
def key?(name) set_for(name).key?(name) end
#keys
: () -> Array
# File 'activemodel/lib/active_model/attribute_set.rb', line 713
def keys @shared.keys | own_only(@own.keys) end
#map(&block)
: () { (ActiveModel::Attribute) -> Attribute } -> ReindexedAttributeSet
# File 'activemodel/lib/active_model/attribute_set.rb', line 813
def map(&block) self.class.new(@shared.map(&block), @own.map(&block)) end
#name_at(index)
: (Integer) -> String?
# File 'activemodel/lib/active_model/attribute_set.rb', line 746
def name_at(index) @own.name_at(index) end
#own_only(names) (private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 883
def own_only(names) names.reject { |name, _| shared?(name) } end
#reset(name)
: (String) -> ActiveModel::Attribute?
# File 'activemodel/lib/active_model/attribute_set.rb', line 767
def reset(name) set_for(name).reset(name) end
#set_for(name) (private)
: (String) -> (ActiveModel::AttributeSet | ReindexedAttributeSet)
# File 'activemodel/lib/active_model/attribute_set.rb', line 878
def set_for(name) shared?(name) ? @shared : @own end
#to_h
Alias for #to_hash.
# File 'activemodel/lib/active_model/attribute_set.rb', line 775
alias :to_h :to_hash
#to_hash Also known as: #to_h
: () -> Hash[String, untyped]
#values
: () -> Array
# File 'activemodel/lib/active_model/attribute_set.rb', line 808
def values each_value.to_a end
#values_before_type_cast
: () -> Hash[String, untyped]
# File 'activemodel/lib/active_model/attribute_set.rb', line 783
def values_before_type_cast @shared.values_before_type_cast.merge(own_only(@own.values_before_type_cast)) end
#values_for_database
: () -> Hash[String, untyped]
# File 'activemodel/lib/active_model/attribute_set.rb', line 788
def values_for_database @shared.values_for_database.merge(own_only(@own.values_for_database)) end
#write_cast_value(name, value)
: (String, untyped) -> Attribute
# File 'activemodel/lib/active_model/attribute_set.rb', line 762
def write_cast_value(name, value) set_for(name).write_cast_value(name, value) end
#write_from_database(name, value)
: (String, untyped) -> Attribute
# File 'activemodel/lib/active_model/attribute_set.rb', line 751
def write_from_database(name, value) set_for(name).write_from_database(name, value) end
#write_from_user(name, value)
: (String, untyped) -> untyped
# File 'activemodel/lib/active_model/attribute_set.rb', line 756
def write_from_user(name, value) raise FrozenError, "can't modify frozen attributes" if frozen? set_for(name).write_from_user(name, value) end