diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 21 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 2 |
3 files changed, 18 insertions, 9 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 4204057737..a5fe6d65d9 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -318,8 +318,8 @@ *Pavel Pravosud* * `HashWithIndifferentAccess` better respects `#to_hash` on objects it - recieves. In particular, `.new`, `#update`, `#merge`, `#replace` all accept - objects which respond to `#to_hash`, even if those objects are not Hashes + receives. In particular, `.new`, `#update`, `#merge`, and `#replace` accept + objects which respond to `#to_hash`, even if those objects are not hashes directly. *Peter Jaros* diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index cd467e13f6..0c8c1d7dfb 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -78,18 +78,21 @@ module ActiveSupport # save # end def run_callbacks(kind, &block) - cbs = send("_#{kind}_callbacks") - if cbs.empty? - yield if block_given? + send "run_#{kind}_callbacks", &block + end + + private + + def _run_callbacks(callbacks, &block) + if callbacks.empty? + block.call if block else - runner = cbs.compile + runner = callbacks.compile e = Filters::Environment.new(self, false, nil, block) runner.call(e).value end end - private - # A hook invoked every time a before callback is halted. # This can be overridden in AS::Callback implementors in order # to provide better debugging/logging. @@ -722,6 +725,12 @@ module ActiveSupport names.each do |name| class_attribute "_#{name}_callbacks" set_callbacks name, CallbackChain.new(name, options) + + module_eval <<-RUBY, __FILE__, __LINE__ + 1 + def run_#{name}_callbacks(&block) + _run_callbacks(_#{name}_callbacks, &block) + end + RUBY end end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index b7a89ed332..3e6d9652bb 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -22,7 +22,7 @@ class TimeZoneTest < ActiveSupport::TestCase assert_instance_of TZInfo::TimezonePeriod, zone.period_for_local(Time.utc(2000)) end - ActiveSupport::TimeZone::MAPPING.keys.each do |name| + ActiveSupport::TimeZone::MAPPING.each_key do |name| define_method("test_map_#{name.downcase.gsub(/[^a-z]/, '_')}_to_tzinfo") do zone = ActiveSupport::TimeZone[name] assert_respond_to zone.tzinfo, :period_for_local |