Skip to content
This repository
Browse code

Remove Array.wrap calls in ActiveRecord

  • Loading branch information...
commit 2958a1e14e1636ae84d3580f4c7a5a7baeab2b8b 1 parent 2a663dc
Rafael Mendonça França rafaelfranca authored
2  activerecord/lib/active_record/associations/association_scope.rb
@@ -15,7 +15,7 @@ def initialize(association)
15 15
16 16 def scope
17 17 scope = klass.unscoped
18   - scope = scope.extending(*Array.wrap(options[:extend]))
  18 + scope = scope.extending(*Array(options[:extend]))
19 19
20 20 # It's okay to just apply all these like this. The options will only be present if the
21 21 # association supports that option; this is enforced by the association builder.
4 activerecord/lib/active_record/associations/builder/collection_association.rb
@@ -32,7 +32,7 @@ def writable?
32 32 private
33 33
34 34 def wrap_block_extension
35   - options[:extend] = Array.wrap(options[:extend])
  35 + options[:extend] = Array(options[:extend])
36 36
37 37 if block_extension
38 38 silence_warnings do
@@ -51,7 +51,7 @@ def define_callback(callback_name)
51 51
52 52 # TODO : why do i need method_defined? I think its because of the inheritance chain
53 53 model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
54   - model.send("#{full_callback_name}=", Array.wrap(options[callback_name.to_sym]))
  54 + model.send("#{full_callback_name}=", Array(options[callback_name.to_sym]))
55 55 end
56 56
57 57 def define_readers
4 activerecord/lib/active_record/associations/collection_association.rb
... ... @@ -1,5 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2   -
3 1 module ActiveRecord
4 2 module Associations
5 3 # = Active Record Association Collection
@@ -67,7 +65,7 @@ def ids_reader
67 65 # Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
68 66 def ids_writer(ids)
69 67 pk_column = reflection.primary_key_column
70   - ids = Array.wrap(ids).reject { |id| id.blank? }
  68 + ids = Array(ids).reject { |id| id.blank? }
71 69 ids.map! { |i| pk_column.type_cast(i) }
72 70 replace(klass.find(ids).index_by { |r| r.id }.values_at(*ids))
73 71 end
2  activerecord/lib/active_record/associations/collection_proxy.rb
@@ -52,7 +52,7 @@ class CollectionProxy # :nodoc:
52 52
53 53 def initialize(association)
54 54 @association = association
55   - Array.wrap(association.options[:extend]).each { |ext| proxy_extend(ext) }
  55 + Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
56 56 end
57 57
58 58 alias_method :new, :build
2  activerecord/lib/active_record/autosave_association.rb
... ... @@ -1,5 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2   -
3 1 module ActiveRecord
4 2 # = Active Record Autosave Association
5 3 #
2  activerecord/lib/active_record/callbacks.rb
... ... @@ -1,5 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2   -
3 1 module ActiveRecord
4 2 # = Active Record Callbacks
5 3 #
9 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
... ... @@ -1,4 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2 1 require 'active_support/deprecation/reporting'
3 2
4 3 module ActiveRecord
@@ -42,7 +41,7 @@ def table_exists?(table_name)
42 41 # # Check an index with a custom name exists
43 42 # index_exists?(:suppliers, :company_id, :name => "idx_company_id"
44 43 def index_exists?(table_name, column_name, options = {})
45   - column_names = Array.wrap(column_name)
  44 + column_names = Array(column_name)
46 45 index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, :column => column_names)
47 46 if options[:unique]
48 47 indexes(table_name).any?{ |i| i.unique && i.name == index_name }
@@ -377,7 +376,7 @@ def rename_index(table_name, old_name, new_name)
377 376 def index_name(table_name, options) #:nodoc:
378 377 if Hash === options # legacy support
379 378 if options[:column]
380   - "index_#{table_name}_on_#{Array.wrap(options[:column]) * '_and_'}"
  379 + "index_#{table_name}_on_#{Array(options[:column]) * '_and_'}"
381 380 elsif options[:name]
382 381 options[:name]
383 382 else
@@ -436,7 +435,7 @@ def initialize_schema_migrations_table
436 435 end
437 436
438 437 def assume_migrated_upto_version(version, migrations_paths = ActiveRecord::Migrator.migrations_paths)
439   - migrations_paths = Array.wrap(migrations_paths)
  438 + migrations_paths = Array(migrations_paths)
440 439 version = version.to_i
441 440 sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)
442 441
@@ -551,7 +550,7 @@ def options_include_default?(options)
551 550 end
552 551
553 552 def add_index_options(table_name, column_name, options = {})
554   - column_names = Array.wrap(column_name)
  553 + column_names = Array(column_name)
555 554 index_name = index_name(table_name, :column => column_names)
556 555
557 556 if Hash === options # legacy support, since this param was a string
3  activerecord/lib/active_record/fixtures.rb
@@ -2,7 +2,6 @@
2 2 require 'yaml'
3 3 require 'zlib'
4 4 require 'active_support/dependencies'
5   -require 'active_support/core_ext/array/wrap'
6 5 require 'active_support/core_ext/object/blank'
7 6 require 'active_support/ordered_hash'
8 7 require 'active_record/fixtures/file'
@@ -783,7 +782,7 @@ def require_fixture_classes(fixture_names = nil)
783 782 end
784 783
785 784 def setup_fixture_accessors(fixture_names = nil)
786   - fixture_names = Array.wrap(fixture_names || fixture_table_names)
  785 + fixture_names = Array(fixture_names || fixture_table_names)
787 786 methods = Module.new do
788 787 fixture_names.each do |fixture_name|
789 788 fixture_name = fixture_name.to_s
5 activerecord/lib/active_record/migration.rb
... ... @@ -1,6 +1,5 @@
1 1 require "active_support/core_ext/module/delegation"
2 2 require "active_support/core_ext/class/attribute_accessors"
3   -require "active_support/core_ext/array/wrap"
4 3
5 4 module ActiveRecord
6 5 # Exception that can be raised to stop migrations from going backwards.
@@ -587,7 +586,7 @@ def proper_table_name(name)
587 586 def migrations_paths
588 587 @migrations_paths ||= ['db/migrate']
589 588 # just to not break things if someone uses: migration_path = some_string
590   - Array.wrap(@migrations_paths)
  589 + Array(@migrations_paths)
591 590 end
592 591
593 592 def migrations_path
@@ -595,7 +594,7 @@ def migrations_path
595 594 end
596 595
597 596 def migrations(paths, subdirectories = true)
598   - paths = Array.wrap(paths)
  597 + paths = Array(paths)
599 598
600 599 glob = subdirectories ? "**/" : ""
601 600 files = Dir[*paths.map { |p| "#{p}/#{glob}[0-9]*_*.rb" }]
4 activerecord/lib/active_record/serialization.rb
@@ -7,8 +7,8 @@ module Serialization
7 7 def serializable_hash(options = nil)
8 8 options = options.try(:clone) || {}
9 9
10   - options[:except] = Array.wrap(options[:except]).map { |n| n.to_s }
11   - options[:except] |= Array.wrap(self.class.inheritance_column)
  10 + options[:except] = Array(options[:except]).map { |n| n.to_s }
  11 + options[:except] |= Array(self.class.inheritance_column)
12 12
13 13 super(options)
14 14 end
3  activerecord/lib/active_record/serializers/xml_serializer.rb
... ... @@ -1,4 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2 1 require 'active_support/core_ext/hash/conversions'
3 2
4 3 module ActiveRecord #:nodoc:
@@ -179,7 +178,7 @@ def to_xml(options = {}, &block)
179 178 class XmlSerializer < ActiveModel::Serializers::Xml::Serializer #:nodoc:
180 179 def initialize(*args)
181 180 super
182   - options[:except] = Array.wrap(options[:except]) | Array.wrap(@serializable.class.inheritance_column)
  181 + options[:except] = Array(options[:except]) | Array(@serializable.class.inheritance_column)
183 182 end
184 183
185 184 class Attribute < ActiveModel::Serializers::Xml::Serializer::Attribute #:nodoc:
4 activerecord/lib/active_record/transactions.rb
@@ -211,7 +211,7 @@ def transaction(options = {}, &block)
211 211 def after_commit(*args, &block)
212 212 options = args.last
213 213 if options.is_a?(Hash) && options[:on]
214   - options[:if] = Array.wrap(options[:if])
  214 + options[:if] = Array(options[:if])
215 215 options[:if] << "transaction_include_action?(:#{options[:on]})"
216 216 end
217 217 set_callback(:commit, :after, *args, &block)
@@ -220,7 +220,7 @@ def after_commit(*args, &block)
220 220 def after_rollback(*args, &block)
221 221 options = args.last
222 222 if options.is_a?(Hash) && options[:on]
223   - options[:if] = Array.wrap(options[:if])
  223 + options[:if] = Array(options[:if])
224 224 options[:if] << "transaction_include_action?(:#{options[:on]})"
225 225 end
226 226 set_callback(:rollback, :after, *args, &block)
4 activerecord/lib/active_record/validations/uniqueness.rb
... ... @@ -1,5 +1,3 @@
1   -require 'active_support/core_ext/array/wrap'
2   -
3 1 module ActiveRecord
4 2 module Validations
5 3 class UniquenessValidator < ActiveModel::EachValidator
@@ -25,7 +23,7 @@ def validate_each(record, attribute, value)
25 23 relation = build_relation(finder_class, table, attribute, value)
26 24 relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.send(:id))) if record.persisted?
27 25
28   - Array.wrap(options[:scope]).each do |scope_item|
  26 + Array(options[:scope]).each do |scope_item|
29 27 scope_value = record.send(scope_item)
30 28 relation = relation.and(table[scope_item].eq(scope_value))
31 29 end

0 comments on commit 2958a1e

Please sign in to comment.
Something went wrong with that request. Please try again.