mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Style update for new Range extensions
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7818 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
fba05826dc
commit
d556f46607
5 changed files with 24 additions and 32 deletions
|
@ -1,7 +1,7 @@
|
|||
require 'active_support/core_ext/range/conversions'
|
||||
require File.dirname(__FILE__) + '/range/overlaps'
|
||||
require File.dirname(__FILE__) + '/range/include_range'
|
||||
require File.dirname(__FILE__) + '/range/blockless_step'
|
||||
require 'active_support/core_ext/range/overlaps'
|
||||
require 'active_support/core_ext/range/include_range'
|
||||
require 'active_support/core_ext/range/blockless_step'
|
||||
|
||||
class Range #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::Range::Conversions
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Range #:nodoc:
|
||||
# Return and array when step is called without a block
|
||||
# Return an array when step is called without a block.
|
||||
module BlocklessStep
|
||||
def self.included(base) #:nodoc:
|
||||
base.alias_method_chain :step, :blockless
|
||||
end
|
||||
|
||||
def self.included(klass) #:nodoc:
|
||||
klass.send(:alias_method, :step_with_block, :step)
|
||||
klass.send(:alias_method, :step, :step_without_block)
|
||||
end
|
||||
|
||||
def step_without_block(value, &block)
|
||||
def step_with_blockless(value, &block)
|
||||
if block_given?
|
||||
step_with_block(value, &block)
|
||||
step_without_blockless(value, &block)
|
||||
else
|
||||
returning [] do |array|
|
||||
step_with_block(value) {|step| array << step }
|
||||
step_without_blockless(value) { |step| array << step }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Range #:nodoc:
|
||||
# Check if a Range includes another Range
|
||||
# Check if a Range includes another Range.
|
||||
module IncludeRange
|
||||
def self.included(base) #:nodoc:
|
||||
base.alias_method_chain :include?, :range
|
||||
end
|
||||
|
||||
def self.included(klass) #:nodoc:
|
||||
klass.send(:alias_method_chain, :include?, :range)
|
||||
end
|
||||
|
||||
def include_with_range?(value)
|
||||
if value.is_a?(::Range)
|
||||
operator = exclude_end? ? :< : :<=
|
||||
|
@ -17,8 +16,7 @@ module ActiveSupport #:nodoc:
|
|||
include_without_range?(value)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
module ActiveSupport #:nodoc:
|
||||
module CoreExtensions #:nodoc:
|
||||
module Range #:nodoc:
|
||||
# Check if Ranges overlap
|
||||
# Check if Ranges overlap.
|
||||
module Overlaps
|
||||
|
||||
def overlaps?(other)
|
||||
include?(other.first) || other.include?(first)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class RangeTest < Test::Unit::TestCase
|
|||
date_range = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
|
||||
assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db)
|
||||
end
|
||||
|
||||
|
||||
def test_overlaps_last_inclusive
|
||||
assert((1..5).overlaps?(5..10))
|
||||
end
|
||||
|
@ -22,11 +22,11 @@ class RangeTest < Test::Unit::TestCase
|
|||
def test_overlaps_first_inclusive
|
||||
assert((5..10).overlaps?(1..5))
|
||||
end
|
||||
|
||||
|
||||
def test_overlaps_first_exclusive
|
||||
assert !(5..10).overlaps?(1...5)
|
||||
end
|
||||
|
||||
|
||||
def test_should_include_identical_inclusive
|
||||
assert((1..10).include?(1..10))
|
||||
end
|
||||
|
@ -46,11 +46,11 @@ class RangeTest < Test::Unit::TestCase
|
|||
def test_should_not_include_overlapping_first
|
||||
assert !(2..8).include?(1..3)
|
||||
end
|
||||
|
||||
|
||||
def test_should_not_include_overlapping_last
|
||||
assert !(2..8).include?(5..9)
|
||||
end
|
||||
|
||||
|
||||
def test_blockless_step
|
||||
assert_equal [1,3,5,7,9], (1..10).step(2)
|
||||
end
|
||||
|
@ -60,5 +60,4 @@ class RangeTest < Test::Unit::TestCase
|
|||
(1..10).step(2) {|i| array << i }
|
||||
assert_equal [1,3,5,7,9], array
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue