Merge pull request #4340 from rafaelfranca/patch-1
Remove more Array.wrap calls
This commit is contained in:
commit
75a630edf3
@ -1,4 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/callbacks'
|
||||
|
||||
module ActiveModel
|
||||
@ -93,7 +92,7 @@ def define_model_callbacks(*callbacks)
|
||||
:only => [:before, :around, :after]
|
||||
}.merge(options)
|
||||
|
||||
types = Array.wrap(options.delete(:only))
|
||||
types = Array(options.delete(:only))
|
||||
|
||||
callbacks.each do |callback|
|
||||
define_callbacks(callback, options)
|
||||
@ -125,7 +124,7 @@ def _define_after_model_callback(klass, callback) #:nodoc:
|
||||
def self.after_#{callback}(*args, &block)
|
||||
options = args.extract_options!
|
||||
options[:prepend] = true
|
||||
options[:if] = Array.wrap(options[:if]) << "!halted && value != false"
|
||||
options[:if] = Array(options[:if]) << "!halted && value != false"
|
||||
set_callback(:#{callback}, :after, *(args << options), &block)
|
||||
end
|
||||
CALLBACK
|
||||
|
@ -1,6 +1,5 @@
|
||||
require 'singleton'
|
||||
require 'active_model/observer_array'
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/module/aliasing'
|
||||
require 'active_support/core_ext/module/remove_method'
|
||||
require 'active_support/core_ext/string/inflections'
|
||||
@ -200,7 +199,7 @@ def observe(*models)
|
||||
# end
|
||||
# end
|
||||
def observed_classes
|
||||
Array.wrap(observed_class)
|
||||
Array(observed_class)
|
||||
end
|
||||
|
||||
# The class observed by default is inferred from the observer's class name:
|
||||
|
@ -73,15 +73,15 @@ def serializable_hash(options = nil)
|
||||
|
||||
attribute_names = attributes.keys.sort
|
||||
if only = options[:only]
|
||||
attribute_names &= Array.wrap(only).map(&:to_s)
|
||||
attribute_names &= Array(only).map(&:to_s)
|
||||
elsif except = options[:except]
|
||||
attribute_names -= Array.wrap(except).map(&:to_s)
|
||||
attribute_names -= Array(except).map(&:to_s)
|
||||
end
|
||||
|
||||
hash = {}
|
||||
attribute_names.each { |n| hash[n] = read_attribute_for_serialization(n) }
|
||||
|
||||
method_names = Array.wrap(options[:methods]).select { |n| respond_to?(n) }
|
||||
method_names = Array(options[:methods]).select { |n| respond_to?(n) }
|
||||
method_names.each { |n| hash[n] = send(n) }
|
||||
|
||||
serializable_add_includes(options) do |association, records, opts|
|
||||
|
@ -1,4 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/class/attribute_accessors'
|
||||
require 'active_support/core_ext/array/conversions'
|
||||
require 'active_support/core_ext/hash/conversions'
|
||||
@ -56,7 +55,7 @@ def serializable_hash
|
||||
end
|
||||
|
||||
def serializable_collection
|
||||
methods = Array.wrap(options[:methods]).map(&:to_s)
|
||||
methods = Array(options[:methods]).map(&:to_s)
|
||||
serializable_hash.map do |name, value|
|
||||
name = name.to_s
|
||||
if methods.include?(name)
|
||||
@ -146,7 +145,7 @@ def add_associations(association, records, opts)
|
||||
|
||||
def add_procs
|
||||
if procs = options.delete(:procs)
|
||||
Array.wrap(procs).each do |proc|
|
||||
Array(procs).each do |proc|
|
||||
if proc.arity == 1
|
||||
proc.call(options)
|
||||
else
|
||||
|
@ -1,5 +1,4 @@
|
||||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
require 'active_support/core_ext/hash/keys'
|
||||
require 'active_support/core_ext/hash/except'
|
||||
@ -133,7 +132,7 @@ def validate(*args, &block)
|
||||
options = args.extract_options!
|
||||
if options.key?(:on)
|
||||
options = options.dup
|
||||
options[:if] = Array.wrap(options[:if])
|
||||
options[:if] = Array(options[:if])
|
||||
options[:if].unshift("validation_context == :#{options[:on]}")
|
||||
end
|
||||
args << options
|
||||
|
@ -30,7 +30,7 @@ module ClassMethods
|
||||
def before_validation(*args, &block)
|
||||
options = args.last
|
||||
if options.is_a?(Hash) && options[:on]
|
||||
options[:if] = Array.wrap(options[:if])
|
||||
options[:if] = Array(options[:if])
|
||||
options[:if].unshift("self.validation_context == :#{options[:on]}")
|
||||
end
|
||||
set_callback(:validation, :before, *args, &block)
|
||||
@ -39,7 +39,7 @@ def before_validation(*args, &block)
|
||||
def after_validation(*args, &block)
|
||||
options = args.extract_options!
|
||||
options[:prepend] = true
|
||||
options[:if] = Array.wrap(options[:if])
|
||||
options[:if] = Array(options[:if])
|
||||
options[:if] << "!halted"
|
||||
options[:if].unshift("self.validation_context == :#{options[:on]}") if options[:on]
|
||||
set_callback(:validation, :after, *(args << options), &block)
|
||||
|
@ -1,4 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require "active_support/core_ext/module/anonymous"
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/core_ext/object/inclusion'
|
||||
@ -137,7 +136,7 @@ class EachValidator < Validator
|
||||
# +options+ reader, however the <tt>:attributes</tt> option will be removed
|
||||
# and instead be made available through the +attributes+ reader.
|
||||
def initialize(options)
|
||||
@attributes = Array.wrap(options.delete(:attributes))
|
||||
@attributes = Array(options.delete(:attributes))
|
||||
raise ":attributes cannot be blank" if @attributes.empty?
|
||||
super
|
||||
check_validity!
|
||||
|
@ -15,7 +15,7 @@ def initialize(association)
|
||||
|
||||
def scope
|
||||
scope = klass.unscoped
|
||||
scope = scope.extending(*Array.wrap(options[:extend]))
|
||||
scope = scope.extending(*Array(options[:extend]))
|
||||
|
||||
# It's okay to just apply all these like this. The options will only be present if the
|
||||
# association supports that option; this is enforced by the association builder.
|
||||
|
@ -32,7 +32,7 @@ def writable?
|
||||
private
|
||||
|
||||
def wrap_block_extension
|
||||
options[:extend] = Array.wrap(options[:extend])
|
||||
options[:extend] = Array(options[:extend])
|
||||
|
||||
if block_extension
|
||||
silence_warnings do
|
||||
@ -51,7 +51,7 @@ def define_callback(callback_name)
|
||||
|
||||
# TODO : why do i need method_defined? I think its because of the inheritance chain
|
||||
model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
|
||||
model.send("#{full_callback_name}=", Array.wrap(options[callback_name.to_sym]))
|
||||
model.send("#{full_callback_name}=", Array(options[callback_name.to_sym]))
|
||||
end
|
||||
|
||||
def define_readers
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
|
||||
module ActiveRecord
|
||||
module Associations
|
||||
# = Active Record Association Collection
|
||||
@ -67,7 +65,7 @@ def ids_reader
|
||||
# Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
|
||||
def ids_writer(ids)
|
||||
pk_column = reflection.primary_key_column
|
||||
ids = Array.wrap(ids).reject { |id| id.blank? }
|
||||
ids = Array(ids).reject { |id| id.blank? }
|
||||
ids.map! { |i| pk_column.type_cast(i) }
|
||||
replace(klass.find(ids).index_by { |r| r.id }.values_at(*ids))
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ class CollectionProxy # :nodoc:
|
||||
|
||||
def initialize(association)
|
||||
@association = association
|
||||
Array.wrap(association.options[:extend]).each { |ext| proxy_extend(ext) }
|
||||
Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
|
||||
end
|
||||
|
||||
alias_method :new, :build
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
|
||||
module ActiveRecord
|
||||
# = Active Record Autosave Association
|
||||
#
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
|
||||
module ActiveRecord
|
||||
# = Active Record Callbacks
|
||||
#
|
||||
|
@ -1,4 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/deprecation/reporting'
|
||||
|
||||
module ActiveRecord
|
||||
@ -42,7 +41,7 @@ def table_exists?(table_name)
|
||||
# # Check an index with a custom name exists
|
||||
# index_exists?(:suppliers, :company_id, :name => "idx_company_id"
|
||||
def index_exists?(table_name, column_name, options = {})
|
||||
column_names = Array.wrap(column_name)
|
||||
column_names = Array(column_name)
|
||||
index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, :column => column_names)
|
||||
if options[:unique]
|
||||
indexes(table_name).any?{ |i| i.unique && i.name == index_name }
|
||||
@ -377,7 +376,7 @@ def rename_index(table_name, old_name, new_name)
|
||||
def index_name(table_name, options) #:nodoc:
|
||||
if Hash === options # legacy support
|
||||
if options[:column]
|
||||
"index_#{table_name}_on_#{Array.wrap(options[:column]) * '_and_'}"
|
||||
"index_#{table_name}_on_#{Array(options[:column]) * '_and_'}"
|
||||
elsif options[:name]
|
||||
options[:name]
|
||||
else
|
||||
@ -436,7 +435,7 @@ def initialize_schema_migrations_table
|
||||
end
|
||||
|
||||
def assume_migrated_upto_version(version, migrations_paths = ActiveRecord::Migrator.migrations_paths)
|
||||
migrations_paths = Array.wrap(migrations_paths)
|
||||
migrations_paths = Array(migrations_paths)
|
||||
version = version.to_i
|
||||
sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
|
||||
|
||||
@ -551,7 +550,7 @@ def options_include_default?(options)
|
||||
end
|
||||
|
||||
def add_index_options(table_name, column_name, options = {})
|
||||
column_names = Array.wrap(column_name)
|
||||
column_names = Array(column_name)
|
||||
index_name = index_name(table_name, :column => column_names)
|
||||
|
||||
if Hash === options # legacy support, since this param was a string
|
||||
|
@ -2,7 +2,6 @@
|
||||
require 'yaml'
|
||||
require 'zlib'
|
||||
require 'active_support/dependencies'
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/ordered_hash'
|
||||
require 'active_record/fixtures/file'
|
||||
@ -783,7 +782,7 @@ def require_fixture_classes(fixture_names = nil)
|
||||
end
|
||||
|
||||
def setup_fixture_accessors(fixture_names = nil)
|
||||
fixture_names = Array.wrap(fixture_names || fixture_table_names)
|
||||
fixture_names = Array(fixture_names || fixture_table_names)
|
||||
methods = Module.new do
|
||||
fixture_names.each do |fixture_name|
|
||||
fixture_name = fixture_name.to_s
|
||||
|
@ -1,6 +1,5 @@
|
||||
require "active_support/core_ext/module/delegation"
|
||||
require "active_support/core_ext/class/attribute_accessors"
|
||||
require "active_support/core_ext/array/wrap"
|
||||
|
||||
module ActiveRecord
|
||||
# Exception that can be raised to stop migrations from going backwards.
|
||||
@ -587,7 +586,7 @@ def proper_table_name(name)
|
||||
def migrations_paths
|
||||
@migrations_paths ||= ['db/migrate']
|
||||
# just to not break things if someone uses: migration_path = some_string
|
||||
Array.wrap(@migrations_paths)
|
||||
Array(@migrations_paths)
|
||||
end
|
||||
|
||||
def migrations_path
|
||||
@ -595,7 +594,7 @@ def migrations_path
|
||||
end
|
||||
|
||||
def migrations(paths, subdirectories = true)
|
||||
paths = Array.wrap(paths)
|
||||
paths = Array(paths)
|
||||
|
||||
glob = subdirectories ? "**/" : ""
|
||||
files = Dir[*paths.map { |p| "#{p}/#{glob}[0-9]*_*.rb" }]
|
||||
|
@ -7,8 +7,8 @@ module Serialization
|
||||
def serializable_hash(options = nil)
|
||||
options = options.try(:clone) || {}
|
||||
|
||||
options[:except] = Array.wrap(options[:except]).map { |n| n.to_s }
|
||||
options[:except] |= Array.wrap(self.class.inheritance_column)
|
||||
options[:except] = Array(options[:except]).map { |n| n.to_s }
|
||||
options[:except] |= Array(self.class.inheritance_column)
|
||||
|
||||
super(options)
|
||||
end
|
||||
|
@ -1,4 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
require 'active_support/core_ext/hash/conversions'
|
||||
|
||||
module ActiveRecord #:nodoc:
|
||||
@ -179,7 +178,7 @@ def to_xml(options = {}, &block)
|
||||
class XmlSerializer < ActiveModel::Serializers::Xml::Serializer #:nodoc:
|
||||
def initialize(*args)
|
||||
super
|
||||
options[:except] = Array.wrap(options[:except]) | Array.wrap(@serializable.class.inheritance_column)
|
||||
options[:except] = Array(options[:except]) | Array(@serializable.class.inheritance_column)
|
||||
end
|
||||
|
||||
class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc:
|
||||
|
@ -211,7 +211,7 @@ def transaction(options = {}, &block)
|
||||
def after_commit(*args, &block)
|
||||
options = args.last
|
||||
if options.is_a?(Hash) && options[:on]
|
||||
options[:if] = Array.wrap(options[:if])
|
||||
options[:if] = Array(options[:if])
|
||||
options[:if] << "transaction_include_action?(:#{options[:on]})"
|
||||
end
|
||||
set_callback(:commit, :after, *args, &block)
|
||||
@ -220,7 +220,7 @@ def after_commit(*args, &block)
|
||||
def after_rollback(*args, &block)
|
||||
options = args.last
|
||||
if options.is_a?(Hash) && options[:on]
|
||||
options[:if] = Array.wrap(options[:if])
|
||||
options[:if] = Array(options[:if])
|
||||
options[:if] << "transaction_include_action?(:#{options[:on]})"
|
||||
end
|
||||
set_callback(:rollback, :after, *args, &block)
|
||||
|
@ -1,5 +1,3 @@
|
||||
require 'active_support/core_ext/array/wrap'
|
||||
|
||||
module ActiveRecord
|
||||
module Validations
|
||||
class UniquenessValidator < ActiveModel::EachValidator
|
||||
@ -25,7 +23,7 @@ def validate_each(record, attribute, value)
|
||||
relation = build_relation(finder_class, table, attribute, value)
|
||||
relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
|
||||
|
||||
Array.wrap(options[:scope]).each do |scope_item|
|
||||
Array(options[:scope]).each do |scope_item|
|
||||
scope_value = record.send(scope_item)
|
||||
relation = relation.and(table[scope_item].eq(scope_value))
|
||||
end
|
||||
@ -81,7 +79,7 @@ module ClassMethods
|
||||
#
|
||||
# class Person < ActiveRecord::Base
|
||||
# validates_uniqueness_of :user_name, :scope => :account_id
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once
|
||||
# per semester for a particular class.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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) }
|
||||
|
Loading…
Reference in New Issue
Block a user