@@ -52,14 +52,41 @@ def initialize_dup(other) # :nodoc:
5252 clear_timestamp_attributes
5353 end
5454
55+ class_methods do
56+ private
57+ def timestamp_attributes_for_create_in_model
58+ timestamp_attributes_for_create . select { |c | column_names . include? ( c ) }
59+ end
60+
61+ def timestamp_attributes_for_update_in_model
62+ timestamp_attributes_for_update . select { |c | column_names . include? ( c ) }
63+ end
64+
65+ def all_timestamp_attributes_in_model
66+ timestamp_attributes_for_create_in_model + timestamp_attributes_for_update_in_model
67+ end
68+
69+ def timestamp_attributes_for_create
70+ [ "created_at" , "created_on" ]
71+ end
72+
73+ def timestamp_attributes_for_update
74+ [ "updated_at" , "updated_on" ]
75+ end
76+
77+ def current_time_from_proper_timezone
78+ default_timezone == :utc ? Time . now . utc : Time . now
79+ end
80+ end
81+
5582 private
5683
5784 def _create_record
5885 if record_timestamps
5986 current_time = current_time_from_proper_timezone
6087
61- all_timestamp_attributes . each do |column |
62- if has_attribute? ( column ) && !attribute_present? ( column )
88+ all_timestamp_attributes_in_model . each do |column |
89+ if !attribute_present? ( column )
6390 write_attribute ( column , current_time )
6491 end
6592 end
@@ -85,41 +112,29 @@ def should_record_timestamps?
85112 end
86113
87114 def timestamp_attributes_for_create_in_model
88- timestamp_attributes_for_create . select { | c | self . class . column_names . include? ( c ) }
115+ self . class . send ( :timestamp_attributes_for_create_in_model )
89116 end
90117
91118 def timestamp_attributes_for_update_in_model
92- timestamp_attributes_for_update . select { | c | self . class . column_names . include? ( c ) }
119+ self . class . send ( :timestamp_attributes_for_update_in_model )
93120 end
94121
95122 def all_timestamp_attributes_in_model
96- timestamp_attributes_for_create_in_model + timestamp_attributes_for_update_in_model
97- end
98-
99- def timestamp_attributes_for_update
100- [ "updated_at" , "updated_on" ]
101- end
102-
103- def timestamp_attributes_for_create
104- [ "created_at" , "created_on" ]
123+ self . class . send ( :all_timestamp_attributes_in_model )
105124 end
106125
107- def all_timestamp_attributes
108- timestamp_attributes_for_create + timestamp_attributes_for_update
126+ def current_time_from_proper_timezone
127+ self . class . send ( :current_time_from_proper_timezone )
109128 end
110129
111- def max_updated_column_timestamp ( timestamp_names = timestamp_attributes_for_update )
130+ def max_updated_column_timestamp ( timestamp_names = self . class . send ( : timestamp_attributes_for_update) )
112131 timestamp_names
113132 . map { |attr | self [ attr ] }
114133 . compact
115134 . map ( &:to_time )
116135 . max
117136 end
118137
119- def current_time_from_proper_timezone
120- self . class . default_timezone == :utc ? Time . now . utc : Time . now
121- end
122-
123138 # Clear attributes and changed_attributes
124139 def clear_timestamp_attributes
125140 all_timestamp_attributes_in_model . each do |attribute_name |
0 commit comments