Class: ActiveModel::AttributeSet
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activemodel/lib/active_model/attribute_set.rb, activemodel/lib/active_model/attribute_set/builder.rb, activemodel/lib/active_model/attribute_set/yaml_encoder.rb |
Class Method Summary
- .new(attributes) ⇒ AttributeSet constructor
Instance Attribute Summary
- #each_value readonly
- #except readonly
- #fetch readonly
- #attributes readonly protected
Instance Method Summary
- #==(other)
- #[](name)
- #[]=(name, value)
- #accessed
- #cast_types
- #deep_dup
- #fetch_value(name, &block)
- #freeze
-
#include?(name)
Alias for #key?.
- #initialize_clone(_)
- #initialize_dup(_)
- #key?(name) ⇒ Boolean (also: #include?)
- #keys
- #map(&block)
- #reset(key)
- #reverse_merge!(target_attributes)
-
#to_h
Alias for #to_hash.
- #to_hash (also: #to_h)
- #values_before_type_cast
- #values_for_database
- #write_cast_value(name, value)
- #write_from_database(name, value)
- #write_from_user(name, value)
- #default_attribute(name) private
Constructor Details
.new(attributes) ⇒ AttributeSet
# File 'activemodel/lib/active_model/attribute_set.rb', line 12
def initialize(attributes) @attributes = attributes end
Instance Attribute Details
#attributes (readonly, protected)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 111
attr_reader :attributes
#each_value (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 10
delegate :each_value, :fetch, :except, to: :attributes
#except (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 10
delegate :each_value, :fetch, :except, to: :attributes
#fetch (readonly)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 10
delegate :each_value, :fetch, :except, to: :attributes
Instance Method Details
#==(other)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 106
def ==(other) other.is_a?(AttributeSet) && attributes == other.send(:attributes) end
#[](name)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 16
def [](name) @attributes[name] || default_attribute(name) end
#[]=(name, value)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 20
def []=(name, value) @attributes[name] = value end
#accessed
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 93
def accessed attributes.each_key.select { |name| self[name].has_been_read? } end
#cast_types
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 24
def cast_types attributes.transform_values(&:type) end
#deep_dup
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 73
def deep_dup AttributeSet.new(attributes.transform_values(&:deep_dup)) end
#default_attribute(name) (private)
[ GitHub ]#fetch_value(name, &block)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 50
def fetch_value(name, &block) self[name].value(&block) end
#freeze
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 68
def freeze attributes.freeze super end
#include?(name)
Alias for #key?.
# File 'activemodel/lib/active_model/attribute_set.rb', line 44
alias :include? :key?
#initialize_clone(_)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 82
def initialize_clone(_) @attributes = @attributes.clone super end
#initialize_dup(_)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 77
def initialize_dup(_) @attributes = @attributes.dup super end
#key?(name) ⇒ Boolean
Also known as: #include?
# File 'activemodel/lib/active_model/attribute_set.rb', line 41
def key?(name) attributes.key?(name) && self[name].initialized? end
#keys
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 46
def keys attributes.each_key.select { |name| self[name].initialized? } end
#map(&block)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 97
def map(&block) new_attributes = attributes.transform_values(&block) AttributeSet.new(new_attributes) end
#reset(key)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 87
def reset(key) if key?(key) write_from_database(key, nil) end end
#reverse_merge!(target_attributes)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 102
def reverse_merge!(target_attributes) attributes.reverse_merge!(target_attributes.attributes) && self end
#to_h
Alias for #to_hash.
# File 'activemodel/lib/active_model/attribute_set.rb', line 39
alias :to_h :to_hash
#to_hash Also known as: #to_h
[ GitHub ]#values_before_type_cast
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 28
def values_before_type_cast attributes.transform_values(&:value_before_type_cast) end
#values_for_database
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 32
def values_for_database attributes.transform_values(&:value_for_database) end
#write_cast_value(name, value)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 64
def write_cast_value(name, value) @attributes[name] = self[name].with_cast_value(value) end
#write_from_database(name, value)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set.rb', line 54
def write_from_database(name, value) @attributes[name] = self[name].with_value_from_database(value) end
#write_from_user(name, value)
# File 'activemodel/lib/active_model/attribute_set.rb', line 58
def write_from_user(name, value) raise FrozenError, "can't modify frozen attributes" if frozen? @attributes[name] = self[name].with_value_from_user(value) value end