From b33bd077fab8e249ba3ddfb7e656c34243c05a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 6 Jan 2012 01:03:53 -0300 Subject: [PATCH] Remove Array.wrap calls in ActiveSupport --- activesupport/lib/active_support/callbacks.rb | 15 +++++++-------- .../lib/active_support/deprecation/behaviors.rb | 3 +-- .../lib/active_support/file_update_checker.rb | 3 +-- activesupport/lib/active_support/json/encoding.rb | 5 ++--- .../lib/active_support/tagged_logging.rb | 2 +- .../lib/active_support/testing/assertions.rb | 3 +-- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index e077cdbe4d..f1d00aab6d 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -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 @@ def clone(chain, klass) 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 @@ def _compile_options(options) 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 @@ def _compile_filter(filter) @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 diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 80dcaf5613..94f8d7133e 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,5 +1,4 @@ require "active_support/notifications" -require "active_support/core_ext/array/wrap" module ActiveSupport module Deprecation @@ -19,7 +18,7 @@ def behavior # 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 diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index a4ad2da137..2ede084e95 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -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 @@ def compile_glob(hash) #:nodoc: end def compile_ext(array) #:nodoc: - array = Array.wrap(array) + array = Array(array) return if array.empty? ".{#{array.join(",")}}" end diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 07b6a940c6..0e1bf4c40b 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -5,7 +5,6 @@ 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 @@ def as_json(options = nil) #:nodoc: # 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 diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 8eae43188d..dc3ca25938 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -19,7 +19,7 @@ def initialize(logger) 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 diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 4e1a58a801..d84595fa8f 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -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 Assertions # 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) }