Permalink
Browse files

Avoid deprecated String#to_a by using Array.wrap(...) instead of Arra…

…y(...)
  • Loading branch information...
1 parent 61355c0 commit 86dda361e2363e27d39cc66d490335d9c7126c7b @jeremy jeremy committed Apr 11, 2010
@@ -1,5 +1,6 @@
-require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/enumerable'
+require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'
module ActiveRecord
@@ -1707,9 +1708,9 @@ def create_extension_modules(association_id, block_extension, extensions)
silence_warnings do
self.parent.const_set(extension_module_name, Module.new(&block_extension))
end
- Array(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
+ Array.wrap(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
else
- Array(extensions)
+ Array.wrap(extensions)
end
end
@@ -1,4 +1,5 @@
require 'set'
+require 'active_support/core_ext/array/wrap'
module ActiveRecord
module Associations
@@ -98,7 +99,7 @@ def to_ary
if @target.is_a?(Array)
@target.to_ary
else
- Array(@target)
+ Array.wrap(@target)
end
end
alias_method :to_a, :to_ary
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module Associations
# This is the root class of all association proxies:
@@ -55,7 +57,7 @@ def initialize(owner, reflection)
@owner, @reflection = owner, reflection
@updated = false
reflection.check_validity!
- Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
+ Array.wrap(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
reset
end
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
# Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic
# before or after an alteration of the object state. This can be used to make sure that associated and
@@ -250,7 +252,7 @@ def method_added(meth)
def before_validation(*args, &block)
options = args.last
if options.is_a?(Hash) && options[:on]
- options[:if] = Array(options[:if])
+ options[:if] = Array.wrap(options[:if])
options[:if] << "@_on_validate == :#{options[:on]}"
end
set_callback(:validation, :before, *args, &block)
@@ -259,7 +261,7 @@ def before_validation(*args, &block)
def after_validation(*args, &block)
options = args.extract_options!
options[:prepend] = true
- options[:if] = Array(options[:if])
+ options[:if] = Array.wrap(options[:if])
options[:if] << "!halted && value != false"
options[:if] << "@_on_validate == :#{options[:on]}" if options[:on]
set_callback(:validation, :after, *(args << options), &block)
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
@@ -267,7 +269,7 @@ def rename_column(table_name, column_name, new_column_name)
# generates
# CREATE UNIQUE INDEX by_branch_party ON accounts(branch_id, party_id)
def add_index(table_name, column_name, options = {})
- column_names = Array(column_name)
+ column_names = Array.wrap(column_name)
index_name = index_name(table_name, :column => column_names)
if Hash === options # legacy support, since this param was a string
@@ -297,7 +299,7 @@ def remove_index(table_name, options = {})
def index_name(table_name, options) #:nodoc:
if Hash === options # legacy support
if options[:column]
- "index_#{table_name}_on_#{Array(options[:column]) * '_and_'}"
+ "index_#{table_name}_on_#{Array.wrap(options[:column]) * '_and_'}"
elsif options[:name]
options[:name]
else
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
module ActiveRecord
@@ -26,7 +27,7 @@ def #{query_method}(*args, &block)
new_relation = clone
new_relation.send(:apply_modules, Module.new(&block)) if block_given?
value = build_where(*args)
- new_relation.#{query_method}_values += [*value] if value.present?
+ new_relation.#{query_method}_values += Array.wrap(value) if value.present?
new_relation
end
CEVAL
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/conversions'
module ActiveRecord #:nodoc:
@@ -186,7 +187,7 @@ def serializable_attributes
end
def serializable_method_attributes
- Array(options[:methods]).inject([]) do |method_attributes, name|
+ Array.wrap(options[:methods]).inject([]) do |method_attributes, name|
method_attributes << MethodAttribute.new(name.to_s, @serializable) if @serializable.respond_to?(name.to_s)
method_attributes
end
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/array/wrap'
+
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator
@@ -19,7 +21,7 @@ def validate_each(record, attribute, value)
relation = table.where(sql, *params)
- Array(options[:scope]).each do |scope_item|
+ Array.wrap(options[:scope]).each do |scope_item|
scope_value = record.send(scope_item)
relation = relation.where(scope_item => scope_value)
end

0 comments on commit 86dda36

Please sign in to comment.