aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
diff options
context:
space:
mode:
authorRoque Pinel <repinel@gmail.com>2015-09-24 21:33:58 -0400
committerRoque Pinel <repinel@gmail.com>2015-10-01 13:04:20 -0400
commite2b3ccd1aa56ae467b0fe5c7466136a4d18fa7ef (patch)
treedeed1044692fa672ae1a9f74ed4164be8cd4337e /activesupport/lib/active_support/callbacks.rb
parent7db7b287ecd616d61dd09147888d02b74d219dd1 (diff)
downloadrails-e2b3ccd1aa56ae467b0fe5c7466136a4d18fa7ef.tar.gz
rails-e2b3ccd1aa56ae467b0fe5c7466136a4d18fa7ef.tar.bz2
rails-e2b3ccd1aa56ae467b0fe5c7466136a4d18fa7ef.zip
Refactor AS::Callbacks halt config and fix the documentation
Move from `AS::Callbacks::CallbackChain.halt_and_display_warning_on_return_false` to `AS::Callbacks.halt_and_display_warning_on_return_false` base on [this discussion](https://github.com/rails/rails/pull/21218#discussion_r39354580) Fix the documentation broken by 0a120a818d413c64ff9867125f0b03788fc306f8
Diffstat (limited to 'activesupport/lib/active_support/callbacks.rb')
-rw-r--r--activesupport/lib/active_support/callbacks.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 3db9ea2ac0..252374e817 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -4,6 +4,7 @@ require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class'
+require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/filters'
require 'active_support/deprecation'
require 'thread'
@@ -66,6 +67,12 @@ module ActiveSupport
CALLBACK_FILTER_TYPES = [:before, :after, :around]
+ # If true, Active Record and Active Model callbacks returning +false+ will
+ # halt the entire callback chain and display a deprecation message.
+ # If false, callback chains will only be halted by calling +throw :abort+.
+ # Defaults to +true+.
+ mattr_accessor(:halt_and_display_warning_on_return_false) { true }
+
# Runs the callbacks for the given event.
#
# Calls the before and around callbacks in the order they were set, yields
@@ -450,12 +457,6 @@ module ActiveSupport
attr_reader :name, :config
- # If true, any callback returning +false+ will halt the entire callback
- # chain and display a deprecation message. If false, callback chains will
- # only be halted by calling +throw :abort+. Defaults to +true+.
- class_attribute :halt_and_display_warning_on_return_false
- self.halt_and_display_warning_on_return_false = true
-
def initialize(name, config)
@name = name
@config = {
@@ -760,7 +761,7 @@ module ActiveSupport
terminate = true
catch(:abort) do
result = result_lambda.call if result_lambda.is_a?(Proc)
- if CallbackChain.halt_and_display_warning_on_return_false && result == false
+ if Callbacks.halt_and_display_warning_on_return_false && result == false
display_deprecation_warning_for_false_terminator
else
terminate = false