diff options
Diffstat (limited to 'activerecord/lib/active_record/timestamp.rb')
-rw-r--r-- | activerecord/lib/active_record/timestamp.rb | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index da075dabd3..9fba8f0aca 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -11,9 +11,6 @@ module ActiveRecord extend ActiveSupport::Concern included do - alias_method_chain :create, :timestamps - alias_method_chain :update, :timestamps - class_inheritable_accessor :record_timestamps, :instance_writer => false self.record_timestamps = true end @@ -39,35 +36,34 @@ module ActiveRecord save! end + private + def create #:nodoc: + if record_timestamps + current_time = current_time_from_proper_timezone - private - def create_with_timestamps #:nodoc: - if record_timestamps - current_time = current_time_from_proper_timezone - - write_attribute('created_at', current_time) if respond_to?(:created_at) && created_at.nil? - write_attribute('created_on', current_time) if respond_to?(:created_on) && created_on.nil? - - write_attribute('updated_at', current_time) if respond_to?(:updated_at) && updated_at.nil? - write_attribute('updated_on', current_time) if respond_to?(:updated_on) && updated_on.nil? - end + write_attribute('created_at', current_time) if respond_to?(:created_at) && created_at.nil? + write_attribute('created_on', current_time) if respond_to?(:created_on) && created_on.nil? - create_without_timestamps + write_attribute('updated_at', current_time) if respond_to?(:updated_at) && updated_at.nil? + write_attribute('updated_on', current_time) if respond_to?(:updated_on) && updated_on.nil? end - def update_with_timestamps(*args) #:nodoc: - if record_timestamps && (!partial_updates? || changed?) - current_time = current_time_from_proper_timezone + super + end - write_attribute('updated_at', current_time) if respond_to?(:updated_at) - write_attribute('updated_on', current_time) if respond_to?(:updated_on) - end + def update(*args) #:nodoc: + if record_timestamps && (!partial_updates? || changed?) + current_time = current_time_from_proper_timezone - update_without_timestamps(*args) - end - - def current_time_from_proper_timezone - self.class.default_timezone == :utc ? Time.now.utc : Time.now + write_attribute('updated_at', current_time) if respond_to?(:updated_at) + write_attribute('updated_on', current_time) if respond_to?(:updated_on) end + + super + end + + def current_time_from_proper_timezone + self.class.default_timezone == :utc ? Time.now.utc : Time.now + end end end
\ No newline at end of file |