activemodel 3.1.12 → 3.2.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +81 -36
 - data/README.rdoc +1 -1
 - data/lib/active_model/attribute_methods.rb +123 -104
 - data/lib/active_model/callbacks.rb +2 -2
 - data/lib/active_model/conversion.rb +26 -2
 - data/lib/active_model/dirty.rb +3 -3
 - data/lib/active_model/errors.rb +63 -51
 - data/lib/active_model/lint.rb +12 -3
 - data/lib/active_model/mass_assignment_security.rb +27 -8
 - data/lib/active_model/mass_assignment_security/permission_set.rb +5 -5
 - data/lib/active_model/mass_assignment_security/sanitizer.rb +42 -6
 - data/lib/active_model/naming.rb +18 -10
 - data/lib/active_model/observer_array.rb +3 -3
 - data/lib/active_model/observing.rb +1 -2
 - data/lib/active_model/secure_password.rb +2 -2
 - data/lib/active_model/serialization.rb +61 -10
 - data/lib/active_model/serializers/json.rb +20 -14
 - data/lib/active_model/serializers/xml.rb +55 -31
 - data/lib/active_model/translation.rb +15 -3
 - data/lib/active_model/validations.rb +1 -1
 - data/lib/active_model/validations/acceptance.rb +3 -1
 - data/lib/active_model/validations/confirmation.rb +3 -1
 - data/lib/active_model/validations/exclusion.rb +5 -3
 - data/lib/active_model/validations/format.rb +4 -2
 - data/lib/active_model/validations/inclusion.rb +5 -3
 - data/lib/active_model/validations/length.rb +22 -10
 - data/lib/active_model/validations/numericality.rb +4 -2
 - data/lib/active_model/validations/presence.rb +5 -3
 - data/lib/active_model/validations/validates.rb +15 -3
 - data/lib/active_model/validations/with.rb +4 -2
 - data/lib/active_model/version.rb +3 -3
 - metadata +21 -28
 - checksums.yaml +0 -7
 
| 
         @@ -43,13 +43,25 @@ module ActiveModel 
     | 
|
| 
       43 
43 
     | 
    
         
             
                #
         
     | 
| 
       44 
44 
     | 
    
         
             
                # Specify +options+ with additional translating options.
         
     | 
| 
       45 
45 
     | 
    
         
             
                def human_attribute_name(attribute, options = {})
         
     | 
| 
       46 
     | 
    
         
            -
                  defaults 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
                  defaults  = []
         
     | 
| 
      
 47 
     | 
    
         
            +
                  parts     = attribute.to_s.split(".", 2)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  attribute = parts.pop
         
     | 
| 
      
 49 
     | 
    
         
            +
                  namespace = parts.pop
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  if namespace
         
     | 
| 
      
 52 
     | 
    
         
            +
                    lookup_ancestors.each do |klass|
         
     | 
| 
      
 53 
     | 
    
         
            +
                      defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
                    defaults << :"#{self.i18n_scope}.attributes.#{namespace}.#{attribute}"
         
     | 
| 
      
 56 
     | 
    
         
            +
                  else
         
     | 
| 
      
 57 
     | 
    
         
            +
                    lookup_ancestors.each do |klass|
         
     | 
| 
      
 58 
     | 
    
         
            +
                      defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
         
     | 
| 
      
 59 
     | 
    
         
            +
                    end
         
     | 
| 
       48 
60 
     | 
    
         
             
                  end
         
     | 
| 
       49 
61 
     | 
    
         | 
| 
       50 
62 
     | 
    
         
             
                  defaults << :"attributes.#{attribute}"
         
     | 
| 
       51 
63 
     | 
    
         
             
                  defaults << options.delete(:default) if options[:default]
         
     | 
| 
       52 
     | 
    
         
            -
                  defaults << attribute. 
     | 
| 
      
 64 
     | 
    
         
            +
                  defaults << attribute.humanize
         
     | 
| 
       53 
65 
     | 
    
         | 
| 
       54 
66 
     | 
    
         
             
                  options.reverse_merge! :count => 1, :default => defaults
         
     | 
| 
       55 
67 
     | 
    
         
             
                  I18n.translate(defaults.shift, options)
         
     | 
| 
         @@ -81,7 +81,7 @@ module ActiveModel 
     | 
|
| 
       81 
81 
     | 
    
         
             
                  #   proc or string should return or evaluate to a true or false value.
         
     | 
| 
       82 
82 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       83 
83 
     | 
    
         
             
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or
         
     | 
| 
       84 
     | 
    
         
            -
                  #   <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 84 
     | 
    
         
            +
                  #   <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       85 
85 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       86 
86 
     | 
    
         
             
                  def validates_each(*attr_names, &block)
         
     | 
| 
       87 
87 
     | 
    
         
             
                    options = attr_names.extract_options!.symbolize_keys
         
     | 
| 
         @@ -49,7 +49,7 @@ module ActiveModel 
     | 
|
| 
       49 
49 
     | 
    
         
             
                  #   before validation.
         
     | 
| 
       50 
50 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
         
     | 
| 
       51 
51 
     | 
    
         
             
                  #   if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
         
     | 
| 
       52 
     | 
    
         
            -
                  #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 52 
     | 
    
         
            +
                  #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       53 
53 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false
         
     | 
| 
       54 
54 
     | 
    
         
             
                  #   value.
         
     | 
| 
       55 
55 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to
         
     | 
| 
         @@ -58,6 +58,8 @@ module ActiveModel 
     | 
|
| 
       58 
58 
     | 
    
         
             
                  #   <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
         
     | 
| 
       59 
59 
     | 
    
         
             
                  #   The method, proc or string should return or evaluate to a true or
         
     | 
| 
       60 
60 
     | 
    
         
             
                  #   false value.
         
     | 
| 
      
 61 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 62 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       61 
63 
     | 
    
         
             
                  def validates_acceptance_of(*attr_names)
         
     | 
| 
       62 
64 
     | 
    
         
             
                    validates_with AcceptanceValidator, _merge_attributes(attr_names)
         
     | 
| 
       63 
65 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -50,7 +50,7 @@ module ActiveModel 
     | 
|
| 
       50 
50 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       51 
51 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine
         
     | 
| 
       52 
52 
     | 
    
         
             
                  #   if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
         
     | 
| 
       53 
     | 
    
         
            -
                  #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 53 
     | 
    
         
            +
                  #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       54 
54 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false
         
     | 
| 
       55 
55 
     | 
    
         
             
                  #   value.
         
     | 
| 
       56 
56 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to
         
     | 
| 
         @@ -58,6 +58,8 @@ module ActiveModel 
     | 
|
| 
       58 
58 
     | 
    
         
             
                  #   <tt>:unless => :skip_validation</tt>, or
         
     | 
| 
       59 
59 
     | 
    
         
             
                  #   <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       60 
60 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 61 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 62 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       61 
63 
     | 
    
         
             
                  def validates_confirmation_of(*attr_names)
         
     | 
| 
       62 
64 
     | 
    
         
             
                    validates_with ConfirmationValidator, _merge_attributes(attr_names)
         
     | 
| 
       63 
65 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'active_support/core_ext/range 
     | 
| 
      
 1 
     | 
    
         
            +
            require 'active_support/core_ext/range'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module ActiveModel
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -54,11 +54,13 @@ module ActiveModel 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  #   validation contexts by default (+nil+), other options are <tt>:create</tt>
         
     | 
| 
       55 
55 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       56 
56 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       57 
     | 
    
         
            -
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 57 
     | 
    
         
            +
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       58 
58 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       59 
59 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       60 
     | 
    
         
            -
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 60 
     | 
    
         
            +
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       61 
61 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 63 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       62 
64 
     | 
    
         
             
                  def validates_exclusion_of(*attr_names)
         
     | 
| 
       63 
65 
     | 
    
         
             
                    validates_with ExclusionValidator, _merge_attributes(attr_names)
         
     | 
| 
       64 
66 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -79,11 +79,13 @@ module ActiveModel 
     | 
|
| 
       79 
79 
     | 
    
         
             
                  #   validation contexts by default (+nil+), other options are <tt>:create</tt>
         
     | 
| 
       80 
80 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       81 
81 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       82 
     | 
    
         
            -
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 82 
     | 
    
         
            +
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       83 
83 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       84 
84 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       85 
     | 
    
         
            -
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 85 
     | 
    
         
            +
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       86 
86 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 87 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 88 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       87 
89 
     | 
    
         
             
                  def validates_format_of(*attr_names)
         
     | 
| 
       88 
90 
     | 
    
         
             
                    validates_with FormatValidator, _merge_attributes(attr_names)
         
     | 
| 
       89 
91 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'active_support/core_ext/range 
     | 
| 
      
 1 
     | 
    
         
            +
            require 'active_support/core_ext/range'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module ActiveModel
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -54,11 +54,13 @@ module ActiveModel 
     | 
|
| 
       54 
54 
     | 
    
         
             
                  #   validation contexts by default (+nil+), other options are <tt>:create</tt>
         
     | 
| 
       55 
55 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       56 
56 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       57 
     | 
    
         
            -
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 57 
     | 
    
         
            +
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       58 
58 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       59 
59 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       60 
     | 
    
         
            -
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 60 
     | 
    
         
            +
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       61 
61 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 63 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       62 
64 
     | 
    
         
             
                  def validates_inclusion_of(*attr_names)
         
     | 
| 
       63 
65 
     | 
    
         
             
                    validates_with InclusionValidator, _merge_attributes(attr_names)
         
     | 
| 
       64 
66 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "active_support/core_ext/string/encoding"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            module ActiveModel
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
              # == Active Model Length Validator
         
     | 
| 
         @@ -6,7 +8,6 @@ module ActiveModel 
     | 
|
| 
       6 
8 
     | 
    
         
             
                  MESSAGES  = { :is => :wrong_length, :minimum => :too_short, :maximum => :too_long }.freeze
         
     | 
| 
       7 
9 
     | 
    
         
             
                  CHECKS    = { :is => :==, :minimum => :>=, :maximum => :<= }.freeze
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                  DEFAULT_TOKENIZER = lambda { |value| value.split(//) }
         
     | 
| 
       10 
11 
     | 
    
         
             
                  RESERVED_OPTIONS  = [:minimum, :maximum, :within, :is, :tokenizer, :too_short, :too_long]
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                  def initialize(options)
         
     | 
| 
         @@ -23,7 +24,7 @@ module ActiveModel 
     | 
|
| 
       23 
24 
     | 
    
         
             
                    keys = CHECKS.keys & options.keys
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
26 
     | 
    
         
             
                    if keys.empty?
         
     | 
| 
       26 
     | 
    
         
            -
                      raise ArgumentError, 'Range unspecified. Specify the :within, :maximum, :minimum, or :is option.'
         
     | 
| 
      
 27 
     | 
    
         
            +
                      raise ArgumentError, 'Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option.'
         
     | 
| 
       27 
28 
     | 
    
         
             
                    end
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
                    keys.each do |key|
         
     | 
| 
         @@ -36,14 +37,11 @@ module ActiveModel 
     | 
|
| 
       36 
37 
     | 
    
         
             
                  end
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                  def validate_each(record, attribute, value)
         
     | 
| 
       39 
     | 
    
         
            -
                    value = ( 
     | 
| 
      
 40 
     | 
    
         
            +
                    value = tokenize(value)
         
     | 
| 
      
 41 
     | 
    
         
            +
                    value_length = value.respond_to?(:length) ? value.length : value.to_s.length
         
     | 
| 
       40 
42 
     | 
    
         | 
| 
       41 
43 
     | 
    
         
             
                    CHECKS.each do |key, validity_check|
         
     | 
| 
       42 
44 
     | 
    
         
             
                      next unless check_value = options[key]
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                      value ||= [] if key == :maximum
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                      value_length = value.respond_to?(:length) ? value.length : value.to_s.length
         
     | 
| 
       47 
45 
     | 
    
         
             
                      next if value_length.send(validity_check, check_value)
         
     | 
| 
       48 
46 
     | 
    
         | 
| 
       49 
47 
     | 
    
         
             
                      errors_options = options.except(*RESERVED_OPTIONS)
         
     | 
| 
         @@ -55,6 +53,18 @@ module ActiveModel 
     | 
|
| 
       55 
53 
     | 
    
         
             
                      record.errors.add(attribute, MESSAGES[key], errors_options)
         
     | 
| 
       56 
54 
     | 
    
         
             
                    end
         
     | 
| 
       57 
55 
     | 
    
         
             
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                  private
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  def tokenize(value)
         
     | 
| 
      
 60 
     | 
    
         
            +
                    if value.kind_of?(String)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      if options[:tokenizer]
         
     | 
| 
      
 62 
     | 
    
         
            +
                        options[:tokenizer].call(value)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      elsif !value.encoding_aware?
         
     | 
| 
      
 64 
     | 
    
         
            +
                        value.mb_chars
         
     | 
| 
      
 65 
     | 
    
         
            +
                      end
         
     | 
| 
      
 66 
     | 
    
         
            +
                    end || value
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
       58 
68 
     | 
    
         
             
                end
         
     | 
| 
       59 
69 
     | 
    
         | 
| 
       60 
70 
     | 
    
         
             
                module HelperMethods
         
     | 
| 
         @@ -83,19 +93,21 @@ module ActiveModel 
     | 
|
| 
       83 
93 
     | 
    
         
             
                  # * <tt>:too_long</tt> - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %{count} characters)").
         
     | 
| 
       84 
94 
     | 
    
         
             
                  # * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is %{count} characters)").
         
     | 
| 
       85 
95 
     | 
    
         
             
                  # * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method and the attribute is the wrong size (default is: "is the wrong length (should be %{count} characters)").
         
     | 
| 
       86 
     | 
    
         
            -
                  # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. 
     | 
| 
      
 96 
     | 
    
         
            +
                  # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
         
     | 
| 
       87 
97 
     | 
    
         
             
                  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
         
     | 
| 
       88 
98 
     | 
    
         
             
                  #   validation contexts by default (+nil+), other options are <tt>:create</tt>
         
     | 
| 
       89 
99 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       90 
100 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       91 
     | 
    
         
            -
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 101 
     | 
    
         
            +
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       92 
102 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       93 
103 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       94 
     | 
    
         
            -
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 104 
     | 
    
         
            +
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       95 
105 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       96 
106 
     | 
    
         
             
                  # * <tt>:tokenizer</tt> - Specifies how to split up the attribute string. (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to
         
     | 
| 
       97 
107 
     | 
    
         
             
                  #   count words as in above example.)
         
     | 
| 
       98 
108 
     | 
    
         
             
                  #   Defaults to <tt>lambda{ |value| value.split(//) }</tt> which counts individual characters.
         
     | 
| 
      
 109 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict.
         
     | 
| 
      
 110 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       99 
111 
     | 
    
         
             
                  def validates_length_of(*attr_names)
         
     | 
| 
       100 
112 
     | 
    
         
             
                    validates_with LengthValidator, _merge_attributes(attr_names)
         
     | 
| 
       101 
113 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -102,11 +102,13 @@ module ActiveModel 
     | 
|
| 
       102 
102 
     | 
    
         
             
                  # * <tt>:odd</tt> - Specifies the value must be an odd number.
         
     | 
| 
       103 
103 
     | 
    
         
             
                  # * <tt>:even</tt> - Specifies the value must be an even number.
         
     | 
| 
       104 
104 
     | 
    
         
             
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       105 
     | 
    
         
            -
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). 
     | 
| 
      
 105 
     | 
    
         
            +
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
         
     | 
| 
       106 
106 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       107 
107 
     | 
    
         
             
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       108 
     | 
    
         
            -
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). 
     | 
| 
      
 108 
     | 
    
         
            +
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
         
     | 
| 
       109 
109 
     | 
    
         
             
                  #   method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 110 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 111 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       110 
112 
     | 
    
         
             
                  #
         
     | 
| 
       111 
113 
     | 
    
         
             
                  # The following checks can also be supplied with a proc or a symbol which corresponds to a method:
         
     | 
| 
       112 
114 
     | 
    
         
             
                  # * <tt>:greater_than</tt>
         
     | 
| 
         @@ -25,16 +25,18 @@ module ActiveModel 
     | 
|
| 
       25 
25 
     | 
    
         
             
                  # This is due to the way Object#blank? handles boolean values: <tt>false.blank? # => true</tt>.
         
     | 
| 
       26 
26 
     | 
    
         
             
                  #
         
     | 
| 
       27 
27 
     | 
    
         
             
                  # Configuration options:
         
     | 
| 
       28 
     | 
    
         
            -
                  # * <tt 
     | 
| 
      
 28 
     | 
    
         
            +
                  # * <tt>:message</tt> - A custom error message (default is: "can't be blank").
         
     | 
| 
       29 
29 
     | 
    
         
             
                  # * <tt>:on</tt> - Specifies when this validation is active. Runs in all
         
     | 
| 
       30 
30 
     | 
    
         
             
                  #   validation contexts by default (+nil+), other options are <tt>:create</tt>
         
     | 
| 
       31 
31 
     | 
    
         
             
                  #   and <tt>:update</tt>.
         
     | 
| 
       32 
     | 
    
         
            -
                  # * <tt 
     | 
| 
      
 32 
     | 
    
         
            +
                  # * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       33 
33 
     | 
    
         
             
                  #   occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
         
     | 
| 
       34 
34 
     | 
    
         
             
                  #   The method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       35 
     | 
    
         
            -
                  # * <tt 
     | 
| 
      
 35 
     | 
    
         
            +
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
         
     | 
| 
       36 
36 
     | 
    
         
             
                  #   not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
         
     | 
| 
       37 
37 
     | 
    
         
             
                  #   The method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
      
 38 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
       38 
40 
     | 
    
         
             
                  #
         
     | 
| 
       39 
41 
     | 
    
         
             
                  def validates_presence_of(*attr_names)
         
     | 
| 
       40 
42 
     | 
    
         
             
                    validates_with PresenceValidator, _merge_attributes(attr_names)
         
     | 
| 
         @@ -70,8 +70,8 @@ module ActiveModel 
     | 
|
| 
       70 
70 
     | 
    
         
             
                  # validator's initializer as +options[:in]+ while other types including
         
     | 
| 
       71 
71 
     | 
    
         
             
                  # regular expressions and strings are passed as +options[:with]+
         
     | 
| 
       72 
72 
     | 
    
         
             
                  #
         
     | 
| 
       73 
     | 
    
         
            -
                  # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+ and +: 
     | 
| 
       74 
     | 
    
         
            -
                  # to one specific validator, as a hash:
         
     | 
| 
      
 73 
     | 
    
         
            +
                  # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+ and +:strict+ 
         
     | 
| 
      
 74 
     | 
    
         
            +
                  # can be given to one specific validator, as a hash:
         
     | 
| 
       75 
75 
     | 
    
         
             
                  #
         
     | 
| 
       76 
76 
     | 
    
         
             
                  #   validates :password, :presence => { :if => :password_required? }, :confirmation => true
         
     | 
| 
       77 
77 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -101,12 +101,24 @@ module ActiveModel 
     | 
|
| 
       101 
101 
     | 
    
         
             
                    end
         
     | 
| 
       102 
102 
     | 
    
         
             
                  end
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
      
 104 
     | 
    
         
            +
                  # This method is used to define validation that can not be corrected by end user
         
     | 
| 
      
 105 
     | 
    
         
            +
                  # and is considered exceptional. 
         
     | 
| 
      
 106 
     | 
    
         
            +
                  # So each validator defined with bang or <tt>:strict</tt> option set to <tt>true</tt>
         
     | 
| 
      
 107 
     | 
    
         
            +
                  # will always raise <tt>ActiveModel::InternalValidationFailed</tt> instead of adding error
         
     | 
| 
      
 108 
     | 
    
         
            +
                  # when validation fails
         
     | 
| 
      
 109 
     | 
    
         
            +
                  # See <tt>validates</tt> for more information about validation itself.
         
     | 
| 
      
 110 
     | 
    
         
            +
                  def validates!(*attributes)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    options = attributes.extract_options!
         
     | 
| 
      
 112 
     | 
    
         
            +
                    options[:strict] = true
         
     | 
| 
      
 113 
     | 
    
         
            +
                    validates(*(attributes << options))
         
     | 
| 
      
 114 
     | 
    
         
            +
                  end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
       104 
116 
     | 
    
         
             
                protected
         
     | 
| 
       105 
117 
     | 
    
         | 
| 
       106 
118 
     | 
    
         
             
                  # When creating custom validators, it might be useful to be able to specify
         
     | 
| 
       107 
119 
     | 
    
         
             
                  # additional default keys. This can be done by overwriting this method.
         
     | 
| 
       108 
120 
     | 
    
         
             
                  def _validates_default_keys
         
     | 
| 
       109 
     | 
    
         
            -
                    [ :if, :unless, :on, :allow_blank, :allow_nil ]
         
     | 
| 
      
 121 
     | 
    
         
            +
                    [ :if, :unless, :on, :allow_blank, :allow_nil , :strict]
         
     | 
| 
       110 
122 
     | 
    
         
             
                  end
         
     | 
| 
       111 
123 
     | 
    
         | 
| 
       112 
124 
     | 
    
         
             
                  def _parse_validates_options(options) #:nodoc:
         
     | 
| 
         @@ -56,12 +56,14 @@ module ActiveModel 
     | 
|
| 
       56 
56 
     | 
    
         
             
                  #   if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
         
     | 
| 
       57 
57 
     | 
    
         
             
                  #   or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>).
         
     | 
| 
       58 
58 
     | 
    
         
             
                  #   The method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       59 
     | 
    
         
            -
                  # * <tt 
     | 
| 
      
 59 
     | 
    
         
            +
                  # * <tt>:unless</tt> - Specifies a method, proc or string to call to
         
     | 
| 
       60 
60 
     | 
    
         
             
                  #   determine if the validation should not occur
         
     | 
| 
       61 
61 
     | 
    
         
             
                  #   (e.g. <tt>:unless => :skip_validation</tt>, or
         
     | 
| 
       62 
62 
     | 
    
         
             
                  #   <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>).
         
     | 
| 
       63 
63 
     | 
    
         
             
                  #   The method, proc or string should return or evaluate to a true or false value.
         
     | 
| 
       64 
     | 
    
         
            -
                  #
         
     | 
| 
      
 64 
     | 
    
         
            +
                  # * <tt>:strict</tt> - Specifies whether validation should be strict. 
         
     | 
| 
      
 65 
     | 
    
         
            +
                  #   See <tt>ActiveModel::Validation#validates!</tt> for more information
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
       65 
67 
     | 
    
         
             
                  # If you pass any additional configuration options, they will be passed
         
     | 
| 
       66 
68 
     | 
    
         
             
                  # to the class and available as <tt>options</tt>:
         
     | 
| 
       67 
69 
     | 
    
         
             
                  #
         
     | 
    
        data/lib/active_model/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,57 +1,49 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: activemodel
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.2.0.rc1
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 6
         
     | 
| 
       5 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
7 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
8 
     | 
    
         
             
            - David Heinemeier Hansson
         
     | 
| 
       8 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-12-20 00:00:00.000000000 Z
         
     | 
| 
       12 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
15 
     | 
    
         
             
              name: activesupport
         
     | 
| 
       15 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &2156002640 !ruby/object:Gem::Requirement
         
     | 
| 
      
 17 
     | 
    
         
            +
                none: false
         
     | 
| 
       16 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - -  
     | 
| 
      
 19 
     | 
    
         
            +
                - - =
         
     | 
| 
       18 
20 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: 3. 
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 3.2.0.rc1
         
     | 
| 
       20 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
     | 
    
         
            -
              version_requirements:  
     | 
| 
       23 
     | 
    
         
            -
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - '='
         
     | 
| 
       25 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: 3.1.12
         
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *2156002640
         
     | 
| 
       27 
25 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
26 
     | 
    
         
             
              name: builder
         
     | 
| 
       29 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &2156000140 !ruby/object:Gem::Requirement
         
     | 
| 
      
 28 
     | 
    
         
            +
                none: false
         
     | 
| 
       30 
29 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
30 
     | 
    
         
             
                - - ~>
         
     | 
| 
       32 
31 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
32 
     | 
    
         
             
                    version: 3.0.0
         
     | 
| 
       34 
33 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       35 
34 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
     | 
    
         
            -
              version_requirements:  
     | 
| 
       37 
     | 
    
         
            -
                requirements:
         
     | 
| 
       38 
     | 
    
         
            -
                - - ~>
         
     | 
| 
       39 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
     | 
    
         
            -
                    version: 3.0.0
         
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *2156000140
         
     | 
| 
       41 
36 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
37 
     | 
    
         
             
              name: i18n
         
     | 
| 
       43 
     | 
    
         
            -
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 38 
     | 
    
         
            +
              requirement: &2156012440 !ruby/object:Gem::Requirement
         
     | 
| 
      
 39 
     | 
    
         
            +
                none: false
         
     | 
| 
       44 
40 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
41 
     | 
    
         
             
                - - ~>
         
     | 
| 
       46 
42 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
43 
     | 
    
         
             
                    version: '0.6'
         
     | 
| 
       48 
44 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       49 
45 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
     | 
    
         
            -
              version_requirements:  
     | 
| 
       51 
     | 
    
         
            -
                requirements:
         
     | 
| 
       52 
     | 
    
         
            -
                - - ~>
         
     | 
| 
       53 
     | 
    
         
            -
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
     | 
    
         
            -
                    version: '0.6'
         
     | 
| 
      
 46 
     | 
    
         
            +
              version_requirements: *2156012440
         
     | 
| 
       55 
47 
     | 
    
         
             
            description: A toolkit for building modeling frameworks like Active Record and Active
         
     | 
| 
       56 
48 
     | 
    
         
             
              Resource. Rich support for attributes, callbacks, validations, observers, serialization,
         
     | 
| 
       57 
49 
     | 
    
         
             
              internationalization, and testing.
         
     | 
| 
         @@ -100,25 +92,26 @@ files: 
     | 
|
| 
       100 
92 
     | 
    
         
             
            - lib/active_model.rb
         
     | 
| 
       101 
93 
     | 
    
         
             
            homepage: http://www.rubyonrails.org
         
     | 
| 
       102 
94 
     | 
    
         
             
            licenses: []
         
     | 
| 
       103 
     | 
    
         
            -
            metadata: {}
         
     | 
| 
       104 
95 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       105 
96 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       106 
97 
     | 
    
         
             
            require_paths:
         
     | 
| 
       107 
98 
     | 
    
         
             
            - lib
         
     | 
| 
       108 
99 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 100 
     | 
    
         
            +
              none: false
         
     | 
| 
       109 
101 
     | 
    
         
             
              requirements:
         
     | 
| 
       110 
     | 
    
         
            -
              - - '>='
         
     | 
| 
      
 102 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
       111 
103 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       112 
104 
     | 
    
         
             
                  version: 1.8.7
         
     | 
| 
       113 
105 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 106 
     | 
    
         
            +
              none: false
         
     | 
| 
       114 
107 
     | 
    
         
             
              requirements:
         
     | 
| 
       115 
     | 
    
         
            -
              - - ' 
     | 
| 
      
 108 
     | 
    
         
            +
              - - ! '>'
         
     | 
| 
       116 
109 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       117 
     | 
    
         
            -
                  version:  
     | 
| 
      
 110 
     | 
    
         
            +
                  version: 1.3.1
         
     | 
| 
       118 
111 
     | 
    
         
             
            requirements: []
         
     | 
| 
       119 
112 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       120 
     | 
    
         
            -
            rubygems_version:  
     | 
| 
      
 113 
     | 
    
         
            +
            rubygems_version: 1.8.7
         
     | 
| 
       121 
114 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       122 
     | 
    
         
            -
            specification_version:  
     | 
| 
      
 115 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
       123 
116 
     | 
    
         
             
            summary: A toolkit for building modeling frameworks (part of Rails).
         
     | 
| 
       124 
117 
     | 
    
         
             
            test_files: []
         
     | 
    
        checksums.yaml
    DELETED
    
    | 
         @@ -1,7 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            ---
         
     | 
| 
       2 
     | 
    
         
            -
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz: 5983e5578edceaef564bb5fc25b9415d898ff381
         
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz: b92519a5a3399e31e92b88678cf834222fac748e
         
     | 
| 
       5 
     | 
    
         
            -
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz: 91286ac9389aa87663fb30f6193458d34d9841e5b3355521d9836a22d7d4b0efc1d52882822f632323687cd642da71bc64ff73ff60a7761147c24c179d3b5c80
         
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz: fb9971035a859a14245cdefe6da5ac3e0c1b88914dcd18aac0a77fbf978f7c8a4b7683f05520e3cd089d43ca425f20150012d8a315f73d748b1e7343b913f367
         
     |