Class: ActiveRecord::AttributeSet
- Inherits:
-
Object
- Object
- ActiveRecord::AttributeSet
- Defined in:
- lib/active_record/attribute_set.rb,
lib/active_record/attribute_set/builder.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Builder
Instance Method Summary collapse
- #[](name) ⇒ Object
- #fetch_value(name) ⇒ Object
- #freeze ⇒ Object
-
#initialize(attributes) ⇒ AttributeSet
constructor
A new instance of AttributeSet.
- #initialize_clone(_) ⇒ Object
- #initialize_dup(_) ⇒ Object
- #key?(name) ⇒ Boolean
- #keys ⇒ Object
- #reset(key) ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
- #values_before_type_cast ⇒ Object
- #write_cast_value(name, value) ⇒ Object
- #write_from_database(name, value) ⇒ Object
- #write_from_user(name, value) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ AttributeSet
Returns a new instance of AttributeSet.
5 6 7 |
# File 'lib/active_record/attribute_set.rb', line 5 def initialize(attributes) @attributes = attributes end |
Instance Method Details
#[](name) ⇒ Object
9 10 11 |
# File 'lib/active_record/attribute_set.rb', line 9 def [](name) attributes[name] || Attribute.null(name) end |
#fetch_value(name) ⇒ Object
30 31 32 |
# File 'lib/active_record/attribute_set.rb', line 30 def fetch_value(name) self[name].value { |n| yield n if block_given? } end |
#freeze ⇒ Object
46 47 48 49 |
# File 'lib/active_record/attribute_set.rb', line 46 def freeze @attributes.freeze super end |
#initialize_clone(_) ⇒ Object
56 57 58 59 |
# File 'lib/active_record/attribute_set.rb', line 56 def initialize_clone(_) @attributes = attributes.clone super end |
#initialize_dup(_) ⇒ Object
51 52 53 54 |
# File 'lib/active_record/attribute_set.rb', line 51 def initialize_dup(_) @attributes = attributes.dup super end |
#key?(name) ⇒ Boolean
22 23 24 |
# File 'lib/active_record/attribute_set.rb', line 22 def key?(name) attributes.key?(name) && self[name].initialized? end |
#keys ⇒ Object
26 27 28 |
# File 'lib/active_record/attribute_set.rb', line 26 def keys attributes.initialized_keys end |
#reset(key) ⇒ Object
61 62 63 64 65 |
# File 'lib/active_record/attribute_set.rb', line 61 def reset(key) if key?(key) write_from_database(key, nil) end end |
#to_hash ⇒ Object Also known as: to_h
17 18 19 |
# File 'lib/active_record/attribute_set.rb', line 17 def to_hash initialized_attributes.transform_values(&:value) end |
#values_before_type_cast ⇒ Object
13 14 15 |
# File 'lib/active_record/attribute_set.rb', line 13 def values_before_type_cast attributes.transform_values(&:value_before_type_cast) end |
#write_cast_value(name, value) ⇒ Object
42 43 44 |
# File 'lib/active_record/attribute_set.rb', line 42 def write_cast_value(name, value) attributes[name] = self[name].with_cast_value(value) end |
#write_from_database(name, value) ⇒ Object
34 35 36 |
# File 'lib/active_record/attribute_set.rb', line 34 def write_from_database(name, value) attributes[name] = self[name].with_value_from_database(value) end |
#write_from_user(name, value) ⇒ Object
38 39 40 |
# File 'lib/active_record/attribute_set.rb', line 38 def write_from_user(name, value) attributes[name] = self[name].with_value_from_user(value) end |