aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/callbacks.rb4
-rw-r--r--activerecord/lib/active_record/locking/optimistic.rb56
-rw-r--r--activerecord/lib/active_record/timestamp.rb35
4 files changed, 51 insertions, 46 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index cbe9b8c4f0..11b965ad6b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Consistent public/protected/private visibility for chained methods. #7813 [dcmanges]
+
* Oracle: fix quoted primary keys and datetime overflow. #7798 [Michael Schoen]
* Consistently quote primary key column names. #7763 [toolmantim]
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index bfe96fd2ed..7a19dcb746 100755
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -227,6 +227,7 @@ module ActiveRecord
callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)
result
end
+ private :initialize_with_callbacks
# Is called _before_ Base.save (regardless of whether it's a create or update save).
def before_save() end
@@ -243,6 +244,7 @@ module ActiveRecord
callback(:after_save)
result
end
+ private :create_or_update_with_callbacks
# Is called _before_ Base.save on new objects that haven't been saved yet (no record exists).
def before_create() end
@@ -255,6 +257,7 @@ module ActiveRecord
callback(:after_create)
result
end
+ private :create_with_callbacks
# Is called _before_ Base.save on existing objects that have a record.
def before_update() end
@@ -268,6 +271,7 @@ module ActiveRecord
callback(:after_update)
result
end
+ private :update_with_callbacks
# Is called _before_ Validations.validate (which is part of the Base.save call).
def before_validation() end
diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb
index 217bd3def7..7b7f87341e 100644
--- a/activerecord/lib/active_record/locking/optimistic.rb
+++ b/activerecord/lib/active_record/locking/optimistic.rb
@@ -23,7 +23,6 @@ module ActiveRecord
# This method uses the same syntax as <tt>set_table_name</tt>
module Optimistic
def self.included(base) #:nodoc:
- super
base.extend ClassMethods
base.cattr_accessor :lock_optimistically, :instance_writer => false
@@ -41,41 +40,42 @@ module ActiveRecord
self.class.locking_enabled?
end
- def attributes_from_column_definition_with_lock
- result = attributes_from_column_definition_without_lock
+ private
+ def attributes_from_column_definition_with_lock
+ result = attributes_from_column_definition_without_lock
- # If the locking column has no default value set,
- # start the lock version at zero. Note we can't use
- # locking_enabled? at this point as @attributes may
- # not have been initialized yet
+ # If the locking column has no default value set,
+ # start the lock version at zero. Note we can't use
+ # locking_enabled? at this point as @attributes may
+ # not have been initialized yet
- if lock_optimistically && result.include?(self.class.locking_column)
- result[self.class.locking_column] ||= 0
- end
+ if lock_optimistically && result.include?(self.class.locking_column)
+ result[self.class.locking_column] ||= 0
+ end
- return result
- end
+ return result
+ end
- def update_with_lock #:nodoc:
- return update_without_lock unless locking_enabled?
+ def update_with_lock #:nodoc:
+ return update_without_lock unless locking_enabled?
- lock_col = self.class.locking_column
- previous_value = send(lock_col)
- send(lock_col + '=', previous_value + 1)
+ lock_col = self.class.locking_column
+ previous_value = send(lock_col)
+ send(lock_col + '=', previous_value + 1)
- affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
- UPDATE #{self.class.table_name}
- SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))}
- WHERE #{self.class.primary_key} = #{quote_value(id)}
- AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
- end_sql
+ affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking")
+ UPDATE #{self.class.table_name}
+ SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false))}
+ WHERE #{self.class.primary_key} = #{quote_value(id)}
+ AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)}
+ end_sql
- unless affected_rows == 1
- raise ActiveRecord::StaleObjectError, "Attempted to update a stale object"
- end
+ unless affected_rows == 1
+ raise ActiveRecord::StaleObjectError, "Attempted to update a stale object"
+ end
- return true
- end
+ return true
+ end
module ClassMethods
DEFAULT_LOCKING_COLUMN = 'lock_version'
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb
index 9c7e798183..77bcbd4c88 100644
--- a/activerecord/lib/active_record/timestamp.rb
+++ b/activerecord/lib/active_record/timestamp.rb
@@ -18,8 +18,6 @@ module ActiveRecord
# <tt>ActiveRecord::Base.default_timezone = :utc</tt>
module Timestamp
def self.included(base) #:nodoc:
- super
-
base.alias_method_chain :create, :timestamps
base.alias_method_chain :update, :timestamps
@@ -27,25 +25,26 @@ module ActiveRecord
base.record_timestamps = true
end
- def create_with_timestamps #:nodoc:
- if record_timestamps
- t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
- write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil?
- write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil?
+ private
+ def create_with_timestamps #:nodoc:
+ if record_timestamps
+ t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
+ write_attribute('created_at', t) if respond_to?(:created_at) && created_at.nil?
+ write_attribute('created_on', t) if respond_to?(:created_on) && created_on.nil?
- write_attribute('updated_at', t) if respond_to?(:updated_at)
- write_attribute('updated_on', t) if respond_to?(:updated_on)
+ write_attribute('updated_at', t) if respond_to?(:updated_at)
+ write_attribute('updated_on', t) if respond_to?(:updated_on)
+ end
+ create_without_timestamps
end
- create_without_timestamps
- end
- def update_with_timestamps #:nodoc:
- if record_timestamps
- t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
- write_attribute('updated_at', t) if respond_to?(:updated_at)
- write_attribute('updated_on', t) if respond_to?(:updated_on)
+ def update_with_timestamps #:nodoc:
+ if record_timestamps
+ t = self.class.default_timezone == :utc ? Time.now.utc : Time.now
+ write_attribute('updated_at', t) if respond_to?(:updated_at)
+ write_attribute('updated_on', t) if respond_to?(:updated_on)
+ end
+ update_without_timestamps
end
- update_without_timestamps
- end
end
end