Permalink
Browse files

Use Array.wrap uniformly

  • Loading branch information...
1 parent c3cea9b commit a98db7c6ef7384d60a1c7f02d43ee601e2647eea @jeremy jeremy committed Mar 27, 2010
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/callbacks'
module ActiveModel
@@ -91,7 +92,7 @@ def define_model_callbacks(*callbacks)
options = callbacks.extract_options!
options = { :terminator => "result == false", :scope => [:kind, :name] }.merge(options)
- types = Array(options.delete(:only))
+ types = Array.wrap(options.delete(:only))
types = [:before, :around, :after] if types.empty?
callbacks.each do |callback|
@@ -124,10 +125,10 @@ def _define_after_model_callback(klass, callback) #:nodoc:
def self.after_#{callback}(*args, &block)
options = args.extract_options!
options[:prepend] = true
- options[:if] = Array(options[:if]) << "!halted && value != false"
+ options[:if] = Array.wrap(options[:if]) << "!halted && value != false"
set_callback(:#{callback}, :after, *(args << options), &block)
end
CALLBACK
end
end
-end
+end
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/inflections'
require 'active_support/ordered_hash'
@@ -206,7 +207,7 @@ def full_messages
full_messages = []
each do |attribute, messages|
- messages = Array(messages)
+ messages = Array.wrap(messages)
next if messages.empty?
if attribute == :base
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/hash/conversions'
@@ -108,7 +109,7 @@ def serializable_attributes
end
def serializable_method_attributes
- Array(options[:methods]).inject([]) do |methods, name|
+ Array.wrap(options[:methods]).inject([]) do |methods, name|
methods << MethodAttribute.new(name.to_s, @serializable) if @serializable.respond_to?(name.to_s)
methods
end
@@ -1,4 +1,5 @@
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_model/errors'
@@ -115,7 +116,7 @@ def validates_each(*attr_names, &block)
def validate(*args, &block)
options = args.last
if options.is_a?(Hash) && options.key?(:on)
- options[:if] = Array(options[:if])
+ options[:if] = Array.wrap(options[:if])
options[:if] << "@_on_validate == :#{options[:on]}"
end
set_callback(:validate, *args, &block)
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require "active_support/core_ext/module/anonymous"
module ActiveModel #:nodoc:
@@ -130,7 +131,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(options.delete(:attributes))
+ @attributes = Array.wrap(options.delete(:attributes))
raise ":attributes cannot be blank" if @attributes.empty?
super
check_validity!

0 comments on commit a98db7c

Please sign in to comment.