Skip to content

Commit

Permalink
Remove Array.wrap call in ActiveModel
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 6, 2012
1 parent 8f309e3 commit 2a663dc
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
5 changes: 2 additions & 3 deletions activemodel/lib/active_model/callbacks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/callbacks'

module ActiveModel
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions activemodel/lib/active_model/observing.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions activemodel/lib/active_model/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
5 changes: 2 additions & 3 deletions activemodel/lib/active_model/serializers/xml.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions activemodel/lib/active_model/validations.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/validations/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions activemodel/lib/active_model/validator.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit 2a663dc

Please sign in to comment.