Class: ActiveRecord::AttributeSet
- Inherits:
-
Object
- Object
- ActiveRecord::AttributeSet
show all
- Defined in:
- activerecord/lib/active_record/attribute_set.rb,
activerecord/lib/active_record/attribute_set/builder.rb,
activerecord/lib/active_record/attribute_set/yaml_encoder.rb
Overview
Defined Under Namespace
Classes: Builder, YAMLEncoder
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ AttributeSet
Returns a new instance of AttributeSet.
10
11
12
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 10
def initialize(attributes)
@attributes = attributes
end
|
Instance Method Details
#==(other) ⇒ Object
99
100
101
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 99
def ==(other)
attributes == other.attributes
end
|
14
15
16
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 14
def [](name)
attributes[name] || Attribute.null(name)
end
|
#[]=(name, value) ⇒ Object
18
19
20
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 18
def []=(name, value)
attributes[name] = value
end
|
90
91
92
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 90
def accessed
attributes.select { |_, attr| attr.has_been_read? }.keys
end
|
68
69
70
71
72
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 68
def deep_dup
self.class.allocate.tap do |copy|
copy.instance_variable_set(:@attributes, attributes.deep_dup)
end
end
|
#fetch_value(name) ⇒ Object
42
43
44
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 42
def fetch_value(name, &block)
self[name].value(&block)
end
|
63
64
65
66
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 63
def freeze
@attributes.freeze
super
end
|
#initialize_clone(_) ⇒ Object
79
80
81
82
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 79
def initialize_clone(_)
@attributes = attributes.clone
super
end
|
#initialize_dup(_) ⇒ Object
74
75
76
77
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 74
def initialize_dup(_)
@attributes = attributes.dup
super
end
|
#key?(name) ⇒ Boolean
31
32
33
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 31
def key?(name)
attributes.key?(name) && self[name].initialized?
end
|
35
36
37
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 35
def keys
attributes.each_key.select { |name| self[name].initialized? }
end
|
#map(&block) ⇒ Object
94
95
96
97
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 94
def map(&block)
new_attributes = attributes.transform_values(&block)
AttributeSet.new(new_attributes)
end
|
#reset(key) ⇒ Object
84
85
86
87
88
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 84
def reset(key)
if key?(key)
write_from_database(key, nil)
end
end
|
#to_hash ⇒ Object
Also known as:
to_h
26
27
28
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 26
def to_hash
initialized_attributes.transform_values(&:value)
end
|
#values_before_type_cast ⇒ Object
22
23
24
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 22
def values_before_type_cast
attributes.transform_values(&:value_before_type_cast)
end
|
#write_cast_value(name, value) ⇒ Object
59
60
61
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 59
def write_cast_value(name, value)
attributes[name] = self[name].with_cast_value(value)
end
|
#write_from_database(name, value) ⇒ Object
51
52
53
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 51
def write_from_database(name, value)
attributes[name] = self[name].with_value_from_database(value)
end
|
#write_from_user(name, value) ⇒ Object
55
56
57
|
# File 'activerecord/lib/active_record/attribute_set.rb', line 55
def write_from_user(name, value)
attributes[name] = self[name].with_value_from_user(value)
end
|