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
|
# File 'lib/smart_time/active_record_extension.rb', line 14
def smart_time(*args)
options = args.
new_attributes = args
first_call = !defined?(@smart_time_attributes)
@smart_time_attributes ||= {}
if new_attributes.empty?
columns.each do |column|
@smart_time_attributes[column.name.to_sym] = options if SmartTime.can_parse?(column.klass)
end
else
new_attributes.each do |attribute|
@smart_time_attributes[attribute.to_sym] = options
end
end
unless first_call
self.class_eval do
def write_attribute(attr_name, value)
if self.class.smart_time_attributes[attr_name.to_sym]
value = SmartTime.parse(value, column_for_attribute(attr_name).klass, self.class.smart_time_attributes[attr_name.to_sym])
end
super(attr_name, value)
end
end
end
end
|