Class: DuckRecord::AttributeSet
- Inherits:
-
Object
- Object
- DuckRecord::AttributeSet
show all
- Defined in:
- lib/duck_record/attribute_set.rb,
lib/duck_record/attribute_set/builder.rb,
lib/duck_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.
8
9
10
|
# File 'lib/duck_record/attribute_set.rb', line 8
def initialize(attributes)
@attributes = attributes
end
|
Instance Method Details
#==(other) ⇒ Object
83
84
85
|
# File 'lib/duck_record/attribute_set.rb', line 83
def ==(other)
attributes == other.attributes
end
|
#[](name) ⇒ Object
12
13
14
|
# File 'lib/duck_record/attribute_set.rb', line 12
def [](name)
attributes[name] || Attribute.null(name)
end
|
#[]=(name, value) ⇒ Object
16
17
18
|
# File 'lib/duck_record/attribute_set.rb', line 16
def []=(name, value)
attributes[name] = value
end
|
#deep_dup ⇒ Object
62
63
64
65
66
|
# File 'lib/duck_record/attribute_set.rb', line 62
def deep_dup
dup.tap do |copy|
copy.instance_variable_set(:@attributes, attributes.deep_dup)
end
end
|
#fetch_value(name) ⇒ Object
40
41
42
|
# File 'lib/duck_record/attribute_set.rb', line 40
def fetch_value(name, &block)
self[name].value(&block)
end
|
#freeze ⇒ Object
57
58
59
60
|
# File 'lib/duck_record/attribute_set.rb', line 57
def freeze
@attributes.freeze
super
end
|
#initialize_clone(_) ⇒ Object
73
74
75
76
|
# File 'lib/duck_record/attribute_set.rb', line 73
def initialize_clone(_)
@attributes = attributes.clone
super
end
|
#initialize_dup(_) ⇒ Object
68
69
70
71
|
# File 'lib/duck_record/attribute_set.rb', line 68
def initialize_dup(_)
@attributes = attributes.dup
super
end
|
#key?(name) ⇒ Boolean
29
30
31
|
# File 'lib/duck_record/attribute_set.rb', line 29
def key?(name)
attributes.key?(name) && self[name].initialized?
end
|
#keys ⇒ Object
33
34
35
|
# File 'lib/duck_record/attribute_set.rb', line 33
def keys
attributes.each_key.select { |name| self[name].initialized? }
end
|
#map(&block) ⇒ Object
78
79
80
81
|
# File 'lib/duck_record/attribute_set.rb', line 78
def map(&block)
new_attributes = attributes.transform_values(&block)
AttributeSet.new(new_attributes)
end
|
#to_hash ⇒ Object
Also known as:
to_h
24
25
26
|
# File 'lib/duck_record/attribute_set.rb', line 24
def to_hash
initialized_attributes.transform_values(&:value)
end
|
#values_before_type_cast ⇒ Object
20
21
22
|
# File 'lib/duck_record/attribute_set.rb', line 20
def values_before_type_cast
attributes.transform_values(&:value_before_type_cast)
end
|
#write_cast_value(name, value) ⇒ Object
53
54
55
|
# File 'lib/duck_record/attribute_set.rb', line 53
def write_cast_value(name, value)
attributes[name] = self[name].with_cast_value(value)
end
|
#write_from_user(name, value) ⇒ Object
49
50
51
|
# File 'lib/duck_record/attribute_set.rb', line 49
def write_from_user(name, value)
attributes[name] = self[name].with_value_from_user(value)
end
|