From 3fbc9d114994f595b31cc89429447efa44105b74 Mon Sep 17 00:00:00 2001 From: Thiago Pradi Date: Thu, 9 Sep 2010 18:54:05 -0300 Subject: [PATCH] use Array.wrap instead of Array() --- actionpack/lib/abstract_controller/callbacks.rb | 4 ++-- actionpack/lib/abstract_controller/layouts.rb | 2 +- actionpack/lib/abstract_controller/view_paths.rb | 4 ++-- actionpack/lib/action_controller/metal.rb | 4 ++-- .../lib/action_controller/metal/mime_responds.rb | 4 ++-- .../lib/action_dispatch/http/mime_negotiation.rb | 2 +- actionpack/lib/action_dispatch/middleware/flash.rb | 2 +- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +++--- .../lib/action_dispatch/routing/route_set.rb | 4 ++-- .../lib/action_dispatch/testing/test_request.rb | 2 +- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- actionpack/test/controller/resources_test.rb | 4 ++-- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 7b0d806..f784eb9 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -32,11 +32,11 @@ module AbstractController # * except - The callback should be run for all actions except this action def _normalize_callback_options(options) if only = options[:only] - only = Array(only).map {|o| "action_name == '#{o}'"}.join(" || ") + only = Array.wrap(only).map {|o| "action_name == '#{o}'"}.join(" || ") options[:per_key] = {:if => only} end if except = options[:except] - except = Array(except).map {|e| "action_name == '#{e}'"}.join(" || ") + except = Array.wrap(except).map {|e| "action_name == '#{e}'"}.join(" || ") options[:per_key] = {:unless => except} end end diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb index 958e7f7..ec2f972 100644 --- a/actionpack/lib/abstract_controller/layouts.rb +++ b/actionpack/lib/abstract_controller/layouts.rb @@ -219,7 +219,7 @@ module AbstractController def layout(layout, conditions = {}) include LayoutConditions unless conditions.empty? - conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} } + conditions.each {|k, v| conditions[k] = Array.wrap(v).map {|a| a.to_s} } self._layout_conditions = conditions @_layout = layout || false # Converts nil to false diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb index 6544c89..c4db66b 100644 --- a/actionpack/lib/abstract_controller/view_paths.rb +++ b/actionpack/lib/abstract_controller/view_paths.rb @@ -38,7 +38,7 @@ module AbstractController # the default view path. You may also provide a custom view path # (see ActionView::ViewPathSet for more information) def append_view_path(path) - self.view_paths = view_paths.dup + Array(path) + self.view_paths = view_paths.dup + Array.wrap(path) end # Prepend a path to the list of view paths for this controller. @@ -48,7 +48,7 @@ module AbstractController # the default view path. You may also provide a custom view path # (see ActionView::ViewPathSet for more information) def prepend_view_path(path) - self.view_paths = Array(path) + view_paths.dup + self.view_paths = Array.wrap(path) + view_paths.dup end # A list of all of the default view paths for this controller. diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index def28a0..16f26aa 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -14,8 +14,8 @@ module ActionController class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc: def initialize(klass, *args) options = args.extract_options! - @only = Array(options.delete(:only)).map(&:to_s) - @except = Array(options.delete(:except)).map(&:to_s) + @only = Array.wrap(options.delete(:only)).map(&:to_s) + @except = Array.wrap(options.delete(:except)).map(&:to_s) args << options unless options.empty? super end diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index c6d4c6d..5feb746 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -39,8 +39,8 @@ module ActionController #:nodoc: def respond_to(*mimes) options = mimes.extract_options! - only_actions = Array(options.delete(:only)) - except_actions = Array(options.delete(:except)) + only_actions = Array.wrap(options.delete(:only)) + except_actions = Array.wrap(options.delete(:except)) new = mimes_for_respond_to.dup mimes.each do |mime| diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index b959aa2..e737287 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -47,7 +47,7 @@ module ActionDispatch @env["action_dispatch.request.formats"] ||= if parameters[:format] - Array(Mime[parameters[:format]]) + Array.wrap(Mime[parameters[:format]]) elsif xhr? || (accept && accept !~ /,\s*\*\/\*/) accepts else diff --git a/actionpack/lib/action_dispatch/middleware/flash.rb b/actionpack/lib/action_dispatch/middleware/flash.rb index 21aeeb2..6cb427e 100644 --- a/actionpack/lib/action_dispatch/middleware/flash.rb +++ b/actionpack/lib/action_dispatch/middleware/flash.rb @@ -165,7 +165,7 @@ module ActionDispatch # Returns the single value for the key you asked to be marked (un)used or the FlashHash itself # if no key is passed. def use(key = nil, used = true) - Array(key || keys).each { |k| used ? @used << k : @used.delete(k) } + Array.wrap(key || keys).each { |k| used ? @used << k : @used.delete(k) } return key ? self[key] : self end end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 8a161b0..dce83db 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -183,7 +183,7 @@ module ActionDispatch def request_method_condition if via = @options[:via] - via = Array(via).map { |m| m.to_s.upcase } + via = Array.wrap(via).map { |m| m.to_s.upcase } { :request_method => Regexp.union(*via) } else { } @@ -621,9 +621,9 @@ module ActionDispatch def actions if only = @options[:only] - Array(only).map(&:to_sym) + Array.wrap(only).map(&:to_sym) elsif except = @options[:except] - default_actions - Array(except).map(&:to_sym) + default_actions - Array.wrap(except).map(&:to_sym) else default_actions end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 956bd2e..23d229b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -130,7 +130,7 @@ module ActionDispatch def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) reset! if regenerate - Array(destinations).each do |dest| + Array.wrap(destinations).each do |dest| dest.__send__(:include, @module) end end @@ -255,7 +255,7 @@ module ActionDispatch end def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false) - Array(destinations).each { |d| d.module_eval { include Helpers } } + Array.wrap(destinations).each { |d| d.module_eval { include Helpers } } named_routes.install(destinations, regenerate_code) end diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index c587a36..6448473 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -66,7 +66,7 @@ module ActionDispatch def accept=(mime_types) @env.delete('action_dispatch.request.accepts') - @env['HTTP_ACCEPT'] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",") + @env['HTTP_ACCEPT'] = Array.wrap(mime_types).collect { |mime_types| mime_types.to_s }.join(",") end def cookies diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index 46af301..d2e5a91 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -101,7 +101,7 @@ module ActionView if text.blank? || phrases.blank? text else - match = Array(phrases).map { |p| Regexp.escape(p) }.join('|') + match = Array.wrap(phrases).map { |p| Regexp.escape(p) }.join('|') text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter]) end.html_safe end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index acb4617..84c4c6c 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1329,9 +1329,9 @@ class ResourcesTest < ActionController::TestCase options = options.merge(:action => action.to_s) path_options = { :path => path, :method => method } - if Array(allowed).include?(action) + if Array.wrap(allowed).include?(action) assert_recognizes options, path_options - elsif Array(not_allowed).include?(action) + elsif Array.wrap(not_allowed).include?(action) assert_not_recognizes options, path_options end end -- 1.6.6.1