diff options
author | wycats <wycats@gmail.com> | 2010-05-09 02:06:05 +0300 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-05-09 02:37:52 +0300 |
commit | d916c62cfc7c59ab6411407a05b946d3dd7535e9 (patch) | |
tree | 653ac4017ea6af4520dd9e6f60d846e19d5e3074 /activerecord/lib/active_record/timestamp.rb | |
parent | 636ffa1f089a51c98fce616191846eaba93d7b87 (diff) | |
download | rails-d916c62cfc7c59ab6411407a05b946d3dd7535e9.tar.gz rails-d916c62cfc7c59ab6411407a05b946d3dd7535e9.tar.bz2 rails-d916c62cfc7c59ab6411407a05b946d3dd7535e9.zip |
eliminate alias_method_chain from ActiveRecord
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 |