blob: 62fb874215b637ccd4ef9f93446d6c9e67d682da (
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
|
module ActiveRecord
module Attributes
class Translator # :nodoc:
def initialize(attributes, column_types)
@attributes = attributes
@column_types = column_types
end
def cast_attribute(attr_name, method)
v = @attributes.fetch(attr_name) { yield }
v && send(method, attr_name, v)
end
def cast_serialized(attr_name, value)
value.unserialized_value
end
def cast_tz_conversion(attr_name, value)
value = cast_column(attr_name, value)
value.acts_like?(:time) ? value.in_time_zone : value
end
def cast_column(attr_name, value)
@column_types[attr_name].type_cast value
end
end
end
end
|