aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2010-03-27 11:50:11 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-03-27 11:50:11 -0700
commita98db7c6ef7384d60a1c7f02d43ee601e2647eea (patch)
treebbb35149bedc0354617f809641413eda637b1cc9 /activemodel/lib
parentc3cea9b59460bb9e67dafcc055f39b8e69542405 (diff)
downloadrails-a98db7c6ef7384d60a1c7f02d43ee601e2647eea.tar.gz
rails-a98db7c6ef7384d60a1c7f02d43ee601e2647eea.tar.bz2
rails-a98db7c6ef7384d60a1c7f02d43ee601e2647eea.zip
Use Array.wrap uniformly
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/callbacks.rb7
-rw-r--r--activemodel/lib/active_model/errors.rb3
-rw-r--r--activemodel/lib/active_model/serializers/xml.rb3
-rw-r--r--activemodel/lib/active_model/validations.rb3
-rw-r--r--activemodel/lib/active_model/validator.rb3
5 files changed, 12 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index a7e0cf90c1..d4e98de57b 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/array/wrap'
require 'active_support/callbacks'
module ActiveModel
@@ -91,7 +92,7 @@ module ActiveModel
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 @@ module ActiveModel
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 \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index d8320275df..a9a54a90e0 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -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 @@ module ActiveModel
full_messages = []
each do |attribute, messages|
- messages = Array(messages)
+ messages = Array.wrap(messages)
next if messages.empty?
if attribute == :base
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index a185204680..c226359ea7 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -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 @@ module ActiveModel
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
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 6013cdb23b..708557f4ae 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -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 @@ module ActiveModel
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)
diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb
index b61f0cb266..b7c52be3f0 100644
--- a/activemodel/lib/active_model/validator.rb
+++ b/activemodel/lib/active_model/validator.rb
@@ -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 @@ module ActiveModel #:nodoc:
# +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!