Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11211 from gsamokovarov/trailing-comma

Further clean-up of ActiveSupport::Callbacks
  • Loading branch information...
commit b7a43ddd39196475cae7510f654eda8487fc1dc6 2 parents 534271d + 269b463
@guilleiguaran guilleiguaran authored
Showing with 9 additions and 10 deletions.
  1. +9 −10 activesupport/lib/active_support/callbacks.rb
View
19 activesupport/lib/active_support/callbacks.rb
@@ -1,5 +1,6 @@
require 'active_support/concern'
require 'active_support/descendants_tracker'
+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'
@@ -542,14 +543,12 @@ def remove_duplicates(callback)
@callbacks = nil
@chain.delete_if { |c| callback.duplicates?(c) }
end
-
end
module ClassMethods
-
def normalize_callback_params(filters, block) # :nodoc:
type = CALLBACK_FILTER_TYPES.include?(filters.first) ? filters.shift : :before
- options = filters.last.is_a?(Hash) ? filters.pop : {}
+ options = filters.extract_options!
filters.unshift(block) if block
[type, filters, options.dup]
end
@@ -662,7 +661,7 @@ def reset_callbacks(name)
# The current object and the return result of the callback will be called
# with the lambda.
#
- # define_callbacks :validate, terminator: ->(target,result) { result == false },
+ # define_callbacks :validate, terminator: ->(target, result) { result == false }
#
# In this example, if any before validate callbacks returns +false+,
# other callbacks are not executed. Defaults to +false+, meaning no value
@@ -718,17 +717,17 @@ def reset_callbacks(name)
#
# would call <tt>Audit#save</tt>.
def define_callbacks(*names)
- config = names.last.is_a?(Hash) ? names.pop : {}
- if config.key?(:terminator) && String === config[:terminator]
+ options = names.extract_options!
+ if options.key?(:terminator) && String === options[:terminator]
ActiveSupport::Deprecation.warn "String based terminators are deprecated, please use a lambda"
- value = config[:terminator]
- l = class_eval "lambda { |result| #{value} }", __FILE__, __LINE__
- config[:terminator] = lambda { |target, result| target.instance_exec(result, &l) }
+ value = options[:terminator]
+ line = class_eval "lambda { |result| #{value} }", __FILE__, __LINE__
+ options[:terminator] = lambda { |target, result| target.instance_exec(result, &line) }
end
names.each do |name|
class_attribute "_#{name}_callbacks"
- set_callbacks name, CallbackChain.new(name, config)
+ set_callbacks name, CallbackChain.new(name, options)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.