aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-06-08 20:32:08 -0500
committerJoshua Peek <josh@joshpeek.com>2009-06-08 20:32:08 -0500
commit28f36279cd484dc66b8b0ca2f0c3d75fd9ac631c (patch)
tree12a75c1f70aa1962bb0ba415562ac29ca76c6404 /activemodel
parent01515f8ecd90150320c7edf1df23850f2a4fdf07 (diff)
downloadrails-28f36279cd484dc66b8b0ca2f0c3d75fd9ac631c.tar.gz
rails-28f36279cd484dc66b8b0ca2f0c3d75fd9ac631c.tar.bz2
rails-28f36279cd484dc66b8b0ca2f0c3d75fd9ac631c.zip
Properly require ActiveModel validation dependencies
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/deprecated_error_methods.rb4
-rw-r--r--activemodel/lib/active_model/errors.rb16
-rw-r--r--activemodel/lib/active_model/validations.rb10
-rw-r--r--activemodel/lib/active_model/validations/acceptance.rb4
-rw-r--r--activemodel/lib/active_model/validations/confirmation.rb4
-rw-r--r--activemodel/lib/active_model/validations/exclusion.rb4
-rw-r--r--activemodel/lib/active_model/validations/format.rb4
-rw-r--r--activemodel/lib/active_model/validations/inclusion.rb4
-rw-r--r--activemodel/lib/active_model/validations/length.rb4
-rw-r--r--activemodel/lib/active_model/validations/numericality.rb4
-rw-r--r--activemodel/lib/active_model/validations/presence.rb6
11 files changed, 35 insertions, 29 deletions
diff --git a/activemodel/lib/active_model/deprecated_error_methods.rb b/activemodel/lib/active_model/deprecated_error_methods.rb
index 433de8931a..dd8050c549 100644
--- a/activemodel/lib/active_model/deprecated_error_methods.rb
+++ b/activemodel/lib/active_model/deprecated_error_methods.rb
@@ -19,7 +19,7 @@ module ActiveModel
ActiveSupport::Deprecation.warn "Errors#add_to_base(msg) has been deprecated, use Errors#[:base] << msg instead"
self[:base] << msg
end
-
+
def invalid?(attribute)
ActiveSupport::Deprecation.warn "Errors#invalid?(attribute) has been deprecated, use Errors#[attribute].any? instead"
self[attribute].any?
@@ -30,4 +30,4 @@ module ActiveModel
to_a.each { |error| yield error }
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 4be91d0505..61bf4a81b8 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/string/inflections'
+
module ActiveModel
class Errors < Hash
include DeprecatedErrorMethods
@@ -23,7 +25,7 @@ module ActiveModel
end
def each
- each_key do |attribute|
+ each_key do |attribute|
self[attribute].each { |error| yield attribute, error }
end
end
@@ -111,15 +113,15 @@ module ActiveModel
end
# Translates an error message in it's default scope (<tt>activemodel.errrors.messages</tt>).
- # Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
- # it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
- # default message (e.g. <tt>activemodel.errors.messages.MESSAGE</tt>). The translated model name,
+ # Error messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it's not there,
+ # it's looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the
+ # default message (e.g. <tt>activemodel.errors.messages.MESSAGE</tt>). The translated model name,
# translated attribute name and the value are available for interpolation.
#
# When using inheritence in your models, it will check all the inherited models too, but only if the model itself
# hasn't been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt>
# error +message+ for the <tt>title</tt> +attribute+, it looks for these translations:
- #
+ #
# <ol>
# <li><tt>activemodel.errors.models.admin.attributes.title.blank</tt></li>
# <li><tt>activemodel.errors.models.admin.blank</tt></li>
@@ -135,7 +137,7 @@ module ActiveModel
klass_ancestors += @base.class.ancestors.reject {|x| x.is_a?(Module)}
defaults = klass_ancestors.map do |klass|
- [ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
+ [ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
:"models.#{klass.name.underscore}.#{message}" ]
end
@@ -155,4 +157,4 @@ module ActiveModel
I18n.translate(key, options)
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 336c2757fc..6b6f51d942 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/array/extract_options'
+require 'active_support/core_ext/hash/keys'
+
module ActiveModel
module Validations
extend ActiveSupport::Concern
@@ -69,10 +72,9 @@ module ActiveModel
end
private
-
- def validation_method(on)
- :validate
- end
+ def validation_method(on)
+ :validate
+ end
end
# Returns the Errors object that holds all information about attribute error messages.
diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb
index 0c9ef51726..b65c9b933d 100644
--- a/activemodel/lib/active_model/validations/acceptance.rb
+++ b/activemodel/lib/active_model/validations/acceptance.rb
@@ -39,10 +39,10 @@ module ActiveModel
validates_each(attr_names,configuration) do |record, attr_name, value|
unless value == configuration[:accept]
- record.errors.add(attr_name, :accepted, :default => configuration[:message])
+ record.errors.add(attr_name, :accepted, :default => configuration[:message])
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb
index b9823172f7..d414224dd2 100644
--- a/activemodel/lib/active_model/validations/confirmation.rb
+++ b/activemodel/lib/active_model/validations/confirmation.rb
@@ -36,10 +36,10 @@ module ActiveModel
validates_each(attr_names, configuration) do |record, attr_name, value|
unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation")
- record.errors.add(attr_name, :confirmation, :default => configuration[:message])
+ record.errors.add(attr_name, :confirmation, :default => configuration[:message])
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb
index 0aa9848ee1..2cfdec97a5 100644
--- a/activemodel/lib/active_model/validations/exclusion.rb
+++ b/activemodel/lib/active_model/validations/exclusion.rb
@@ -29,10 +29,10 @@ module ActiveModel
validates_each(attr_names, configuration) do |record, attr_name, value|
if enum.include?(value)
- record.errors.add(attr_name, :exclusion, :default => configuration[:message], :value => value)
+ record.errors.add(attr_name, :exclusion, :default => configuration[:message], :value => value)
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index 8efce8ba2b..6f3b668bf0 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -32,10 +32,10 @@ module ActiveModel
validates_each(attr_names, configuration) do |record, attr_name, value|
unless value.to_s =~ configuration[:with]
- record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
+ record.errors.add(attr_name, :invalid, :default => configuration[:message], :value => value)
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index a4bc8fe035..0d7dc5cd64 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -29,10 +29,10 @@ module ActiveModel
validates_each(attr_names, configuration) do |record, attr_name, value|
unless enum.include?(value)
- record.errors.add(attr_name, :inclusion, :default => configuration[:message], :value => value)
+ record.errors.add(attr_name, :inclusion, :default => configuration[:message], :value => value)
end
end
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index bb9a269a02..db0439d447 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -81,7 +81,7 @@ module ActiveModel
validates_each(attrs, options) do |record, attr, value|
value = options[:tokenizer].call(value) if value.kind_of?(String)
unless !value.nil? and value.size.method(validity_checks[option])[option_value]
- record.errors.add(attr, key, :default => custom_message, :count => option_value)
+ record.errors.add(attr, key, :default => custom_message, :count => option_value)
end
end
end
@@ -90,4 +90,4 @@ module ActiveModel
alias_method :validates_size_of, :validates_length_of
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index 79fca2f1ea..ada6e28594 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -71,7 +71,7 @@ module ActiveModel
case option
when :odd, :even
unless raw_value.to_i.method(ALL_NUMERICALITY_CHECKS[option])[]
- record.errors.add(attr_name, option, :value => raw_value, :default => configuration[:message])
+ record.errors.add(attr_name, option, :value => raw_value, :default => configuration[:message])
end
else
unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]
@@ -83,4 +83,4 @@ module ActiveModel
end
end
end
-end \ No newline at end of file
+end
diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb
index 518bc8a952..72d6b1c6f0 100644
--- a/activemodel/lib/active_model/validations/presence.rb
+++ b/activemodel/lib/active_model/validations/presence.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/blank'
+
module ActiveModel
module Validations
module ClassMethods
@@ -16,7 +18,7 @@ module ActiveModel
#
# Configuration options:
# * <tt>message</tt> - A custom error message (default is: "can't be blank").
- # * <tt>on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>,
+ # * <tt>on</tt> - Specifies when this validation is active (default is <tt>:save</tt>, other options <tt>:create</tt>,
# <tt>:update</tt>).
# * <tt>if</tt> - Specifies a method, proc or string to call to determine if the validation should
# occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
@@ -36,4 +38,4 @@ module ActiveModel
end
end
end
-end \ No newline at end of file
+end