diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-21 21:19:18 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-21 21:19:18 -0700 |
commit | dab58bee2a0c982f0b09abdf3dd4fa4a53c485a8 (patch) | |
tree | 25fb1ccc1b6447aa510393c78975f23ba9acb69d /activesupport/lib | |
parent | 95a2ccc0117c48725d296761dd025646406a6270 (diff) | |
parent | 8e1d3cd4909c83bbceb7df00da71ec1393a90f6e (diff) | |
download | rails-dab58bee2a0c982f0b09abdf3dd4fa4a53c485a8.tar.gz rails-dab58bee2a0c982f0b09abdf3dd4fa4a53c485a8.tar.bz2 rails-dab58bee2a0c982f0b09abdf3dd4fa4a53c485a8.zip |
Merge pull request #10096 from benofsky/fix_skipping_object_callback_filters
Fixes skipping object callback filters
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 357d9adde3..f95bae580c 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -133,7 +133,15 @@ module ActiveSupport end def matches?(_kind, _filter) - @kind == _kind && @filter == _filter + _filter_matches = false + + if @_is_object_filter + _filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false)) + else + _filter_matches = (@filter == _filter) + end + + @kind == _kind && _filter_matches end def duplicates?(other) @@ -236,6 +244,16 @@ module ActiveSupport @compiled_options = conditions.flatten.join(" && ") end + def _method_name_for_object_filter(kind, filter, append_next_id = true) + class_name = filter.kind_of?(Class) ? filter.to_s : filter.class.to_s + class_name.gsub!(/<|>|#/, '') + class_name.gsub!(/\/|:/, "_") + + method_name = "_callback_#{kind}_#{class_name}" + method_name << "_#{next_id}" if append_next_id + method_name + end + # Filters support: # # Arrays:: Used in conditions. This is used to specify @@ -257,6 +275,8 @@ module ActiveSupport # a method is created that calls the before_foo method # on the object. def _compile_filter(filter) + @_is_object_filter = false + case filter when Array filter.map {|f| _compile_filter(f)} @@ -271,7 +291,8 @@ module ActiveSupport method_name << (filter.arity == 1 ? "(self)" : " self, Proc.new ") else - method_name = "_callback_#{@kind}_#{next_id}" + method_name = _method_name_for_object_filter(kind, filter) + @_is_object_filter = true @klass.send(:define_method, "#{method_name}_object") { filter } _normalize_legacy_filter(kind, filter) |