diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-09-22 12:33:12 -0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-09-22 12:33:12 -0700 |
commit | ffc8abd41b420c2eac58fe92fb03e494e690e43f (patch) | |
tree | d11382412cc23219eead5e3ed5c3d1d07bcf5970 /activesupport/lib/active_support | |
parent | 2356aed7701603feb5564ec3ddb9d57760eaa8a4 (diff) | |
parent | f9e60c74b665954407f7de3265ae6996fc5e4635 (diff) | |
download | rails-ffc8abd41b420c2eac58fe92fb03e494e690e43f.tar.gz rails-ffc8abd41b420c2eac58fe92fb03e494e690e43f.tar.bz2 rails-ffc8abd41b420c2eac58fe92fb03e494e690e43f.zip |
Merge pull request #11474 from bogdan/time-with-zone-succ
Prevent server blow up when iterating over TimeWithZone Range
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/range.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/range/each.rb | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/range.rb b/activesupport/lib/active_support/core_ext/range.rb index 1d8b1ede5a..9368e81235 100644 --- a/activesupport/lib/active_support/core_ext/range.rb +++ b/activesupport/lib/active_support/core_ext/range.rb @@ -1,3 +1,4 @@ require 'active_support/core_ext/range/conversions' require 'active_support/core_ext/range/include_range' require 'active_support/core_ext/range/overlaps' +require 'active_support/core_ext/range/each' diff --git a/activesupport/lib/active_support/core_ext/range/each.rb b/activesupport/lib/active_support/core_ext/range/each.rb new file mode 100644 index 0000000000..d51ea2e944 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/each.rb @@ -0,0 +1,24 @@ +require 'active_support/core_ext/module/aliasing' +require 'active_support/core_ext/object/acts_like' + +class Range #:nodoc: + + def each_with_time_with_zone(&block) + ensure_iteration_allowed + each_without_time_with_zone(&block) + end + alias_method_chain :each, :time_with_zone + + def step_with_time_with_zone(n = 1, &block) + ensure_iteration_allowed + step_without_time_with_zone(n, &block) + end + alias_method_chain :step, :time_with_zone + + private + def ensure_iteration_allowed + if first.acts_like?(:time) + raise TypeError, "can't iterate from #{first.class}" + end + end +end |