blob: 102ef17e16aa138e561e163a2dff9340b4c6e5d9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
module ActiveRecord
class AttributeSet # :nodoc:
delegate :[], :[]=, :fetch, :include?, :keys, :each_with_object, to: :attributes
def initialize(attributes)
@attributes = attributes
end
def update(other)
attributes.update(other.attributes)
end
def freeze
@attributes.freeze
super
end
def initialize_dup(_)
@attributes = attributes.dup
attributes.each do |key, attr|
attributes[key] = attr.dup
end
super
end
def initialize_clone(_)
@attributes = attributes.clone
super
end
class Builder
def initialize(types)
@types = types
end
def build_from_database(values, additional_types = {})
attributes = values.each_with_object({}) do |(name, value), hash|
type = additional_types.fetch(name, @types[name])
hash[name] = Attribute.from_database(value, type)
end
AttributeSet.new(attributes)
end
end
protected
attr_reader :attributes
end
end
|