1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove Array.wrap calls in ActiveSupport

This commit is contained in:
Rafael Mendonça França 2012-01-06 01:03:53 -03:00
parent 2958a1e14e
commit b33bd077fa
6 changed files with 13 additions and 18 deletions

View file

@ -1,6 +1,5 @@
require 'active_support/concern'
require 'active_support/descendants_tracker'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/singleton_class'
@ -121,12 +120,12 @@ module ActiveSupport
end
def normalize_options!(options)
options[:if] = Array.wrap(options[:if])
options[:unless] = Array.wrap(options[:unless])
options[:if] = Array(options[:if])
options[:unless] = Array(options[:unless])
options[:per_key] ||= {}
options[:per_key][:if] = Array.wrap(options[:per_key][:if])
options[:per_key][:unless] = Array.wrap(options[:per_key][:unless])
options[:per_key][:if] = Array(options[:per_key][:if])
options[:per_key][:unless] = Array(options[:per_key][:unless])
end
def name
@ -246,11 +245,11 @@ module ActiveSupport
conditions = ["true"]
unless options[:if].empty?
conditions << Array.wrap(_compile_filter(options[:if]))
conditions << Array(_compile_filter(options[:if]))
end
unless options[:unless].empty?
conditions << Array.wrap(_compile_filter(options[:unless])).map {|f| "!#{f}"}
conditions << Array(_compile_filter(options[:unless])).map {|f| "!#{f}"}
end
conditions.flatten.join(" && ")
@ -295,7 +294,7 @@ module ActiveSupport
@klass.send(:define_method, "#{method_name}_object") { filter }
_normalize_legacy_filter(kind, filter)
scopes = Array.wrap(chain.config[:scope])
scopes = Array(chain.config[:scope])
method_to_call = scopes.map{ |s| s.is_a?(Symbol) ? send(s) : s }.join("_")
@klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1

View file

@ -1,5 +1,4 @@
require "active_support/notifications"
require "active_support/core_ext/array/wrap"
module ActiveSupport
module Deprecation
@ -19,7 +18,7 @@ module ActiveSupport
# ActiveSupport::Deprecation.behavior = :stderr
# ActiveSupport::Deprecation.behavior = [:stderr, :log]
def behavior=(behavior)
@behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
end
end

View file

@ -1,4 +1,3 @@
require "active_support/core_ext/array/wrap"
require "active_support/core_ext/array/extract_options"
module ActiveSupport
@ -113,7 +112,7 @@ module ActiveSupport
end
def compile_ext(array) #:nodoc:
array = Array.wrap(array)
array = Array(array)
return if array.empty?
".{#{array.join(",")}}"
end

View file

@ -5,7 +5,6 @@ require 'active_support/ordered_hash'
require 'bigdecimal'
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/object/instance_variables'
@ -228,9 +227,9 @@ class Hash
# create a subset of the hash by applying :only or :except
subset = if options
if attrs = options[:only]
slice(*Array.wrap(attrs))
slice(*Array(attrs))
elsif attrs = options[:except]
except(*Array.wrap(attrs))
except(*Array(attrs))
else
self
end

View file

@ -19,7 +19,7 @@ module ActiveSupport
def tagged(*new_tags)
tags = current_tags
new_tags = Array.wrap(new_tags).flatten.reject(&:blank?)
new_tags = Array(new_tags).flatten.reject(&:blank?)
tags.concat new_tags
yield
ensure

View file

@ -1,4 +1,3 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
module ActiveSupport
@ -45,7 +44,7 @@ module ActiveSupport
# post :delete, :id => ...
# end
def assert_difference(expression, difference = 1, message = nil, &block)
expressions = Array.wrap expression
expressions = Array(expression)
exps = expressions.map { |e|
e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }