Class: ActiveModel::LazyAttributeSet
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AttributeSet
|
|
Instance Chain:
self,
AttributeSet
|
|
Inherits: |
ActiveModel::AttributeSet
|
Defined in: | activemodel/lib/active_model/attribute_set/builder.rb |
Class Method Summary
- .new(values, types, additional_types, default_attributes, attributes = {}) ⇒ LazyAttributeSet constructor
AttributeSet
- Inherited
Instance Attribute Summary
- #additional_types readonly private
- #default_attributes readonly private
- #types readonly private
- #values readonly private
AttributeSet
- Inherited
Instance Method Summary
- #fetch_value(name, &block)
- #key?(name) ⇒ Boolean
- #keys
- #attributes protected
- #default_attribute(name, value_present = true, value = values.fetch(name) { value_present = false }) private
AttributeSet
- Inherited
Constructor Details
.new(values, types, additional_types, default_attributes, attributes = {}) ⇒ LazyAttributeSet
# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 22
def initialize(values, types, additional_types, default_attributes, attributes = {}) super(attributes) @values = values @types = types @additional_types = additional_types @default_attributes = default_attributes @casted_values = {} @materialized = false end
Instance Attribute Details
#additional_types (readonly, private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 71
attr_reader :values, :types, :additional_types, :default_attributes
#default_attributes (readonly, private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 71
attr_reader :values, :types, :additional_types, :default_attributes
#types (readonly, private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 71
attr_reader :values, :types, :additional_types, :default_attributes
#values (readonly, private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 71
attr_reader :values, :types, :additional_types, :default_attributes
Instance Method Details
#attributes (protected)
[ GitHub ]#default_attribute(name, value_present = true, value = values.fetch(name) { value_present = false }) (private)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 73
def default_attribute( name, value_present = true, value = values.fetch(name) { value_present = false } ) type = additional_types.fetch(name, types[name]) if value_present @attributes[name] = Attribute.from_database(name, value, type, @casted_values[name]) elsif types.key?(name) if attr = default_attributes[name] @attributes[name] = attr.dup else @attributes[name] = Attribute.uninitialized(name, type) end else Attribute.null(name) end end
#fetch_value(name, &block)
[ GitHub ]# File 'activemodel/lib/active_model/attribute_set/builder.rb', line 41
def fetch_value(name, &block) if attr = @attributes[name] return attr.value(&block) end @casted_values.fetch(name) do value_present = true value = values.fetch(name) { value_present = false } if value_present type = additional_types.fetch(name, types[name]) @casted_values[name] = type.deserialize(value) else attr = default_attribute(name, value_present, value) attr.value(&block) end end end