mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use run_callbacks; the generated _run_<name>_callbacks method is not a public interface.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
9666b6a625
commit
57bc25c5f8
14 changed files with 28 additions and 31 deletions
|
@ -25,7 +25,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
_run_call_callbacks do
|
run_callbacks :call do
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,12 +43,12 @@ module ActionDispatch
|
||||||
|
|
||||||
# Execute all prepare callbacks.
|
# Execute all prepare callbacks.
|
||||||
def self.prepare!
|
def self.prepare!
|
||||||
new(nil).send(:_run_prepare_callbacks)
|
new(nil).run_callbacks :prepare
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute all cleanup callbacks.
|
# Execute all cleanup callbacks.
|
||||||
def self.cleanup!
|
def self.cleanup!
|
||||||
new(nil).send(:_run_cleanup_callbacks)
|
new(nil).run_callbacks :cleanup
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -64,12 +64,12 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
_run_prepare_callbacks
|
run_callbacks :prepare
|
||||||
response = @app.call(env)
|
response = @app.call(env)
|
||||||
response[2].extend(CleanupOnClose)
|
response[2].extend(CleanupOnClose)
|
||||||
response
|
response
|
||||||
rescue Exception
|
rescue Exception
|
||||||
_run_cleanup_callbacks
|
run_callbacks :cleanup
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ modules:
|
||||||
define_model_callbacks :create
|
define_model_callbacks :create
|
||||||
|
|
||||||
def create
|
def create
|
||||||
_run_create_callbacks do
|
run_callbacks :create do
|
||||||
# Your create action methods here
|
# Your create action methods here
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,14 +24,11 @@ module ActiveModel
|
||||||
# you want callbacks on in a block so that the callbacks get a chance to fire:
|
# you want callbacks on in a block so that the callbacks get a chance to fire:
|
||||||
#
|
#
|
||||||
# def create
|
# def create
|
||||||
# _run_create_callbacks do
|
# run_callbacks :create do
|
||||||
# # Your create action methods here
|
# # Your create action methods here
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The _run_<method_name>_callbacks methods are dynamically created when you extend
|
|
||||||
# the <tt>ActiveModel::Callbacks</tt> module.
|
|
||||||
#
|
|
||||||
# Then in your class, you can use the +before_create+, +after_create+ and +around_create+
|
# Then in your class, you can use the +before_create+, +after_create+ and +around_create+
|
||||||
# methods, just as you would in an Active Record module.
|
# methods, just as you would in an Active Record module.
|
||||||
#
|
#
|
||||||
|
|
|
@ -207,7 +207,7 @@ module ActiveModel
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def run_validations!
|
def run_validations!
|
||||||
_run_validate_callbacks
|
run_callbacks :validate
|
||||||
errors.empty?
|
errors.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,7 +50,7 @@ module ActiveModel
|
||||||
|
|
||||||
# Overwrite run validations to include callbacks.
|
# Overwrite run validations to include callbacks.
|
||||||
def run_validations!
|
def run_validations!
|
||||||
_run_validation_callbacks { super }
|
run_callbacks(:validation) { super }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CallbacksTest < ActiveModel::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
_run_create_callbacks do
|
run_callbacks :create do
|
||||||
@callbacks << :create
|
@callbacks << :create
|
||||||
@valid
|
@valid
|
||||||
end
|
end
|
||||||
|
@ -92,7 +92,7 @@ class CallbacksTest < ActiveModel::TestCase
|
||||||
def callback1; self.history << 'callback1'; end
|
def callback1; self.history << 'callback1'; end
|
||||||
def callback2; self.history << 'callback2'; end
|
def callback2; self.history << 'callback2'; end
|
||||||
def create
|
def create
|
||||||
_run_create_callbacks {}
|
run_callbacks(:create) {}
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1400,7 +1400,7 @@ MSG
|
||||||
self.attributes = attributes unless attributes.nil?
|
self.attributes = attributes unless attributes.nil?
|
||||||
|
|
||||||
result = yield self if block_given?
|
result = yield self if block_given?
|
||||||
_run_initialize_callbacks
|
run_callbacks :initialize
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1437,8 +1437,8 @@ MSG
|
||||||
@aggregation_cache = {}
|
@aggregation_cache = {}
|
||||||
@readonly = @destroyed = @marked_for_destruction = false
|
@readonly = @destroyed = @marked_for_destruction = false
|
||||||
@new_record = false
|
@new_record = false
|
||||||
_run_find_callbacks
|
run_callbacks :find
|
||||||
_run_initialize_callbacks
|
run_callbacks :initialize
|
||||||
end
|
end
|
||||||
|
|
||||||
# Specifies how the record is dumped by +Marshal+.
|
# Specifies how the record is dumped by +Marshal+.
|
||||||
|
|
|
@ -237,25 +237,25 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy #:nodoc:
|
def destroy #:nodoc:
|
||||||
_run_destroy_callbacks { super }
|
run_callbacks(:destroy) { super }
|
||||||
end
|
end
|
||||||
|
|
||||||
def touch(*) #:nodoc:
|
def touch(*) #:nodoc:
|
||||||
_run_touch_callbacks { super }
|
run_callbacks(:touch) { super }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_or_update #:nodoc:
|
def create_or_update #:nodoc:
|
||||||
_run_save_callbacks { super }
|
run_callbacks(:save) { super }
|
||||||
end
|
end
|
||||||
|
|
||||||
def create #:nodoc:
|
def create #:nodoc:
|
||||||
_run_create_callbacks { super }
|
run_callbacks(:create) { super }
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(*) #:nodoc:
|
def update(*) #:nodoc:
|
||||||
_run_update_callbacks { super }
|
run_callbacks(:update) { super }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -212,7 +212,7 @@ module ActiveRecord
|
||||||
# calling +checkout+ on this pool.
|
# calling +checkout+ on this pool.
|
||||||
def checkin(conn)
|
def checkin(conn)
|
||||||
@connection_mutex.synchronize do
|
@connection_mutex.synchronize do
|
||||||
conn.send(:_run_checkin_callbacks) do
|
conn.run_callbacks :checkin do
|
||||||
@checked_out.delete conn
|
@checked_out.delete conn
|
||||||
@queue.signal
|
@queue.signal
|
||||||
end
|
end
|
||||||
|
|
|
@ -259,7 +259,7 @@ module ActiveRecord
|
||||||
|
|
||||||
# Call the after_commit callbacks
|
# Call the after_commit callbacks
|
||||||
def committed! #:nodoc:
|
def committed! #:nodoc:
|
||||||
_run_commit_callbacks
|
run_callbacks :commit
|
||||||
ensure
|
ensure
|
||||||
clear_transaction_record_state
|
clear_transaction_record_state
|
||||||
end
|
end
|
||||||
|
@ -267,7 +267,7 @@ module ActiveRecord
|
||||||
# Call the after rollback callbacks. The restore_state argument indicates if the record
|
# Call the after rollback callbacks. The restore_state argument indicates if the record
|
||||||
# state should be rolled back to the beginning or just to the last savepoint.
|
# state should be rolled back to the beginning or just to the last savepoint.
|
||||||
def rolledback!(force_restore_state = false) #:nodoc:
|
def rolledback!(force_restore_state = false) #:nodoc:
|
||||||
_run_rollback_callbacks
|
run_callbacks :rollback
|
||||||
ensure
|
ensure
|
||||||
restore_transaction_record_state(force_restore_state)
|
restore_transaction_record_state(force_restore_state)
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,14 +31,14 @@ module ActiveSupport
|
||||||
def run(runner)
|
def run(runner)
|
||||||
result = '.'
|
result = '.'
|
||||||
begin
|
begin
|
||||||
_run_setup_callbacks do
|
run_callbacks :setup do
|
||||||
result = super
|
result = super
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
result = runner.puke(self.class, method_name, e)
|
result = runner.puke(self.class, method_name, e)
|
||||||
ensure
|
ensure
|
||||||
begin
|
begin
|
||||||
_run_teardown_callbacks
|
run_callbacks :teardown
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
result = runner.puke(self.class, method_name, e)
|
result = runner.puke(self.class, method_name, e)
|
||||||
end
|
end
|
||||||
|
@ -62,7 +62,7 @@ module ActiveSupport
|
||||||
|
|
||||||
begin
|
begin
|
||||||
begin
|
begin
|
||||||
_run_setup_callbacks do
|
run_callbacks :setup do
|
||||||
setup
|
setup
|
||||||
__send__(@method_name)
|
__send__(@method_name)
|
||||||
mocha_verify(mocha_counter) if mocha_counter
|
mocha_verify(mocha_counter) if mocha_counter
|
||||||
|
@ -77,7 +77,7 @@ module ActiveSupport
|
||||||
ensure
|
ensure
|
||||||
begin
|
begin
|
||||||
teardown
|
teardown
|
||||||
_run_teardown_callbacks
|
run_callbacks :teardown
|
||||||
rescue Test::Unit::AssertionFailedError => e
|
rescue Test::Unit::AssertionFailedError => e
|
||||||
add_failure(e.message, e.backtrace)
|
add_failure(e.message, e.backtrace)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -70,7 +70,7 @@ class EmptyParent
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch
|
def dispatch
|
||||||
_run_dispatch_callbacks
|
run_callbacks :dispatch
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ module CallbacksTest
|
||||||
def after_save1; self.history << :after; end
|
def after_save1; self.history << :after; end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
self.send(:_run_save_callbacks) do
|
run_callbacks :save do
|
||||||
raise 'boom'
|
raise 'boom'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue