activemodel 4.2.11.3 → 5.0.7.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +149 -56
- data/MIT-LICENSE +1 -1
- data/README.rdoc +8 -16
- data/lib/active_model/attribute_assignment.rb +52 -0
- data/lib/active_model/attribute_methods.rb +16 -16
- data/lib/active_model/callbacks.rb +3 -3
- data/lib/active_model/conversion.rb +5 -5
- data/lib/active_model/dirty.rb +41 -40
- data/lib/active_model/errors.rb +175 -68
- data/lib/active_model/forbidden_attributes_protection.rb +3 -2
- data/lib/active_model/gem_version.rb +5 -5
- data/lib/active_model/lint.rb +32 -28
- data/lib/active_model/locale/en.yml +2 -1
- data/lib/active_model/model.rb +3 -4
- data/lib/active_model/naming.rb +5 -4
- data/lib/active_model/secure_password.rb +2 -9
- data/lib/active_model/serialization.rb +36 -9
- data/lib/active_model/type/big_integer.rb +13 -0
- data/lib/active_model/type/binary.rb +50 -0
- data/lib/active_model/type/boolean.rb +21 -0
- data/lib/active_model/type/date.rb +54 -0
- data/lib/active_model/type/date_time.rb +44 -0
- data/lib/active_model/type/decimal.rb +66 -0
- data/lib/active_model/type/decimal_without_scale.rb +11 -0
- data/lib/active_model/type/float.rb +25 -0
- data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +35 -0
- data/lib/active_model/type/helpers/mutable.rb +18 -0
- data/lib/active_model/type/helpers/numeric.rb +34 -0
- data/lib/active_model/type/helpers/time_value.rb +77 -0
- data/lib/active_model/type/helpers.rb +4 -0
- data/lib/active_model/type/immutable_string.rb +29 -0
- data/lib/active_model/type/integer.rb +66 -0
- data/lib/active_model/type/registry.rb +64 -0
- data/lib/active_model/type/string.rb +24 -0
- data/lib/active_model/type/text.rb +11 -0
- data/lib/active_model/type/time.rb +42 -0
- data/lib/active_model/type/unsigned_integer.rb +15 -0
- data/lib/active_model/type/value.rb +116 -0
- data/lib/active_model/type.rb +59 -0
- data/lib/active_model/validations/absence.rb +1 -1
- data/lib/active_model/validations/acceptance.rb +57 -9
- data/lib/active_model/validations/callbacks.rb +3 -3
- data/lib/active_model/validations/clusivity.rb +4 -3
- data/lib/active_model/validations/confirmation.rb +16 -4
- data/lib/active_model/validations/exclusion.rb +3 -1
- data/lib/active_model/validations/format.rb +1 -1
- data/lib/active_model/validations/helper_methods.rb +13 -0
- data/lib/active_model/validations/inclusion.rb +3 -3
- data/lib/active_model/validations/length.rb +49 -18
- data/lib/active_model/validations/numericality.rb +20 -11
- data/lib/active_model/validations/validates.rb +1 -1
- data/lib/active_model/validations/with.rb +0 -10
- data/lib/active_model/validations.rb +34 -1
- data/lib/active_model/validator.rb +5 -5
- data/lib/active_model/version.rb +1 -1
- data/lib/active_model.rb +4 -2
- metadata +31 -22
- data/lib/active_model/serializers/xml.rb +0 -238
@@ -30,14 +30,15 @@ module ActiveModel
|
|
30
30
|
@delimiter ||= options[:in] || options[:within]
|
31
31
|
end
|
32
32
|
|
33
|
-
# In Ruby
|
33
|
+
# In Ruby 2.2 <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all
|
34
34
|
# possible values in the range for equality, which is slower but more accurate.
|
35
35
|
# <tt>Range#cover?</tt> uses the previous logic of comparing a value with the range
|
36
|
-
# endpoints, which is fast but is only accurate on Numeric, Time,
|
36
|
+
# endpoints, which is fast but is only accurate on Numeric, Time, Date,
|
37
|
+
# or DateTime ranges.
|
37
38
|
def inclusion_method(enumerable)
|
38
39
|
if enumerable.is_a? Range
|
39
40
|
case enumerable.first
|
40
|
-
when Numeric, Time, DateTime
|
41
|
+
when Numeric, Time, DateTime, Date
|
41
42
|
:cover?
|
42
43
|
else
|
43
44
|
:include?
|
@@ -3,14 +3,16 @@ module ActiveModel
|
|
3
3
|
module Validations
|
4
4
|
class ConfirmationValidator < EachValidator # :nodoc:
|
5
5
|
def initialize(options)
|
6
|
-
super
|
6
|
+
super({ case_sensitive: true }.merge!(options))
|
7
7
|
setup!(options[:class])
|
8
8
|
end
|
9
9
|
|
10
10
|
def validate_each(record, attribute, value)
|
11
|
-
if (confirmed = record.send("#{attribute}_confirmation"))
|
12
|
-
|
13
|
-
|
11
|
+
if (confirmed = record.send("#{attribute}_confirmation"))
|
12
|
+
unless confirmation_value_equal?(record, attribute, value, confirmed)
|
13
|
+
human_attribute_name = record.class.human_attribute_name(attribute)
|
14
|
+
record.errors.add(:"#{attribute}_confirmation", :confirmation, options.except(:case_sensitive).merge!(attribute: human_attribute_name))
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -24,6 +26,14 @@ module ActiveModel
|
|
24
26
|
:"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation=")
|
25
27
|
end.compact)
|
26
28
|
end
|
29
|
+
|
30
|
+
def confirmation_value_equal?(record, attribute, value, confirmed)
|
31
|
+
if !options[:case_sensitive] && value.is_a?(String)
|
32
|
+
value.casecmp(confirmed) == 0
|
33
|
+
else
|
34
|
+
value == confirmed
|
35
|
+
end
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
39
|
module HelperMethods
|
@@ -55,6 +65,8 @@ module ActiveModel
|
|
55
65
|
# Configuration options:
|
56
66
|
# * <tt>:message</tt> - A custom error message (default is: "doesn't match
|
57
67
|
# <tt>%{translated_attribute_name}</tt>").
|
68
|
+
# * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by
|
69
|
+
# non-text columns (+true+ by default).
|
58
70
|
#
|
59
71
|
# There is also a list of default options supported by every validator:
|
60
72
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
@@ -29,7 +29,9 @@ module ActiveModel
|
|
29
29
|
# Configuration options:
|
30
30
|
# * <tt>:in</tt> - An enumerable object of items that the value shouldn't
|
31
31
|
# be part of. This can be supplied as a proc, lambda or symbol which returns an
|
32
|
-
# enumerable. If the enumerable is a range the test
|
32
|
+
# enumerable. If the enumerable is a numerical, time or datetime range the test
|
33
|
+
# is performed with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When
|
34
|
+
# using a proc or lambda the instance under validation is passed as an argument.
|
33
35
|
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
34
36
|
# <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>.
|
35
37
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
|
@@ -77,7 +77,7 @@ module ActiveModel
|
|
77
77
|
# with: ->(person) { person.admin? ? /\A[a-z0-9][a-z0-9_\-]*\z/i : /\A[a-z][a-z0-9_\-]*\z/i }
|
78
78
|
# end
|
79
79
|
#
|
80
|
-
# Note: use <tt>\A</tt> and <tt>\
|
80
|
+
# Note: use <tt>\A</tt> and <tt>\z</tt> to match the start and end of the
|
81
81
|
# string, <tt>^</tt> and <tt>$</tt> match the start/end of a line.
|
82
82
|
#
|
83
83
|
# Due to frequent misuse of <tt>^</tt> and <tt>$</tt>, you need to pass
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
module HelperMethods # :nodoc:
|
4
|
+
private
|
5
|
+
def _merge_attributes(attr_names)
|
6
|
+
options = attr_names.extract_options!.symbolize_keys
|
7
|
+
attr_names.flatten!
|
8
|
+
options[:attributes] = attr_names
|
9
|
+
options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -28,9 +28,9 @@ module ActiveModel
|
|
28
28
|
# Configuration options:
|
29
29
|
# * <tt>:in</tt> - An enumerable object of available items. This can be
|
30
30
|
# supplied as a proc, lambda or symbol which returns an enumerable. If the
|
31
|
-
# enumerable is a numerical range the test is performed
|
32
|
-
# otherwise with <tt>include?</tt>. When using
|
33
|
-
# under validation is passed as an argument.
|
31
|
+
# enumerable is a numerical, time or datetime range the test is performed
|
32
|
+
# with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When using
|
33
|
+
# a proc or lambda the instance under validation is passed as an argument.
|
34
34
|
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
35
35
|
# * <tt>:message</tt> - Specifies a custom error message (default is: "is
|
36
36
|
# not included in the list").
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
require "active_support/core_ext/string/strip"
|
2
2
|
|
3
|
-
|
3
|
+
module ActiveModel
|
4
4
|
module Validations
|
5
5
|
class LengthValidator < EachValidator # :nodoc:
|
6
6
|
MESSAGES = { is: :wrong_length, minimum: :too_short, maximum: :too_long }.freeze
|
@@ -18,6 +18,27 @@ module ActiveModel
|
|
18
18
|
options[:minimum] = 1
|
19
19
|
end
|
20
20
|
|
21
|
+
if options[:tokenizer]
|
22
|
+
ActiveSupport::Deprecation.warn(<<-EOS.strip_heredoc)
|
23
|
+
The `:tokenizer` option is deprecated, and will be removed in Rails 5.1.
|
24
|
+
You can achieve the same functionality by defining an instance method
|
25
|
+
with the value that you want to validate the length of. For example,
|
26
|
+
|
27
|
+
validates_length_of :essay, minimum: 100,
|
28
|
+
tokenizer: ->(str) { str.scan(/\w+/) }
|
29
|
+
|
30
|
+
should be written as
|
31
|
+
|
32
|
+
validates_length_of :words_in_essay, minimum: 100
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def words_in_essay
|
37
|
+
essay.scan(/\w+/)
|
38
|
+
end
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
|
21
42
|
super
|
22
43
|
end
|
23
44
|
|
@@ -38,7 +59,7 @@ module ActiveModel
|
|
38
59
|
end
|
39
60
|
|
40
61
|
def validate_each(record, attribute, value)
|
41
|
-
value = tokenize(value)
|
62
|
+
value = tokenize(record, value)
|
42
63
|
value_length = value.respond_to?(:length) ? value.length : value.to_s.length
|
43
64
|
errors_options = options.except(*RESERVED_OPTIONS)
|
44
65
|
|
@@ -59,10 +80,14 @@ module ActiveModel
|
|
59
80
|
end
|
60
81
|
|
61
82
|
private
|
62
|
-
|
63
|
-
|
64
|
-
if
|
65
|
-
|
83
|
+
def tokenize(record, value)
|
84
|
+
tokenizer = options[:tokenizer]
|
85
|
+
if tokenizer && value.kind_of?(String)
|
86
|
+
if tokenizer.kind_of?(Proc)
|
87
|
+
tokenizer.call(value)
|
88
|
+
elsif record.respond_to?(tokenizer)
|
89
|
+
record.send(tokenizer, value)
|
90
|
+
end
|
66
91
|
end || value
|
67
92
|
end
|
68
93
|
|
@@ -73,8 +98,9 @@ module ActiveModel
|
|
73
98
|
|
74
99
|
module HelperMethods
|
75
100
|
|
76
|
-
# Validates that the specified
|
77
|
-
# supplied. Only one option can be used at a time
|
101
|
+
# Validates that the specified attributes match the length restrictions
|
102
|
+
# supplied. Only one constraint option can be used at a time apart from
|
103
|
+
# +:minimum+ and +:maximum+ that can be combined together:
|
78
104
|
#
|
79
105
|
# class Person < ActiveRecord::Base
|
80
106
|
# validates_length_of :first_name, maximum: 30
|
@@ -84,34 +110,39 @@ module ActiveModel
|
|
84
110
|
# validates_length_of :user_name, within: 6..20, too_long: 'pick a shorter name', too_short: 'pick a longer name'
|
85
111
|
# validates_length_of :zip_code, minimum: 5, too_short: 'please enter at least 5 characters'
|
86
112
|
# validates_length_of :smurf_leader, is: 4, message: "papa is spelled with 4 characters... don't play me."
|
87
|
-
# validates_length_of :
|
88
|
-
#
|
113
|
+
# validates_length_of :words_in_essay, minimum: 100, too_short: 'Your essay must be at least 100 words.'
|
114
|
+
#
|
115
|
+
# private
|
116
|
+
#
|
117
|
+
# def words_in_essay
|
118
|
+
# essay.scan(/\w+/)
|
119
|
+
# end
|
89
120
|
# end
|
90
121
|
#
|
91
|
-
#
|
122
|
+
# Constraint options:
|
123
|
+
#
|
92
124
|
# * <tt>:minimum</tt> - The minimum size of the attribute.
|
93
125
|
# * <tt>:maximum</tt> - The maximum size of the attribute. Allows +nil+ by
|
94
|
-
# default if not used with
|
126
|
+
# default if not used with +:minimum+.
|
95
127
|
# * <tt>:is</tt> - The exact size of the attribute.
|
96
128
|
# * <tt>:within</tt> - A range specifying the minimum and maximum size of
|
97
129
|
# the attribute.
|
98
130
|
# * <tt>:in</tt> - A synonym (or alias) for <tt>:within</tt>.
|
131
|
+
#
|
132
|
+
# Other options:
|
133
|
+
#
|
99
134
|
# * <tt>:allow_nil</tt> - Attribute may be +nil+; skip validation.
|
100
135
|
# * <tt>:allow_blank</tt> - Attribute may be blank; skip validation.
|
101
136
|
# * <tt>:too_long</tt> - The error message if the attribute goes over the
|
102
137
|
# maximum (default is: "is too long (maximum is %{count} characters)").
|
103
138
|
# * <tt>:too_short</tt> - The error message if the attribute goes under the
|
104
|
-
# minimum (default is: "is too short (
|
139
|
+
# minimum (default is: "is too short (minimum is %{count} characters)").
|
105
140
|
# * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt>
|
106
141
|
# method and the attribute is the wrong size (default is: "is the wrong
|
107
142
|
# length (should be %{count} characters)").
|
108
143
|
# * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>,
|
109
144
|
# <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate
|
110
145
|
# <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
|
111
|
-
# * <tt>:tokenizer</tt> - Specifies how to split up the attribute string.
|
112
|
-
# (e.g. <tt>tokenizer: ->(str) { str.scan(/\w+/) }</tt> to count words
|
113
|
-
# as in above example). Defaults to <tt>->(value) { value.split(//) }</tt>
|
114
|
-
# which counts individual characters.
|
115
146
|
#
|
116
147
|
# There is also a list of default options supported by every validator:
|
117
148
|
# +:if+, +:unless+, +:on+ and +:strict+.
|
@@ -20,7 +20,7 @@ module ActiveModel
|
|
20
20
|
def validate_each(record, attr_name, value)
|
21
21
|
before_type_cast = :"#{attr_name}_before_type_cast"
|
22
22
|
|
23
|
-
raw_value = record.send(before_type_cast) if record.respond_to?(before_type_cast)
|
23
|
+
raw_value = record.send(before_type_cast) if record.respond_to?(before_type_cast) && record.send(before_type_cast) != value
|
24
24
|
raw_value ||= value
|
25
25
|
|
26
26
|
if record_attribute_changed_in_place?(record, attr_name)
|
@@ -29,16 +29,20 @@ module ActiveModel
|
|
29
29
|
|
30
30
|
return if options[:allow_nil] && raw_value.nil?
|
31
31
|
|
32
|
-
unless
|
32
|
+
unless is_number?(raw_value)
|
33
33
|
record.errors.add(attr_name, :not_a_number, filtered_options(raw_value))
|
34
34
|
return
|
35
35
|
end
|
36
36
|
|
37
|
-
if allow_only_integer?(record)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
if allow_only_integer?(record) && !is_integer?(raw_value)
|
38
|
+
record.errors.add(attr_name, :not_an_integer, filtered_options(raw_value))
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
if raw_value.is_a?(Numeric)
|
43
|
+
value = raw_value
|
44
|
+
else
|
45
|
+
value = parse_raw_value_as_a_number(raw_value)
|
42
46
|
end
|
43
47
|
|
44
48
|
options.slice(*CHECKS.keys).each do |option, option_value|
|
@@ -64,14 +68,19 @@ module ActiveModel
|
|
64
68
|
|
65
69
|
protected
|
66
70
|
|
71
|
+
def is_number?(raw_value)
|
72
|
+
!parse_raw_value_as_a_number(raw_value).nil?
|
73
|
+
rescue ArgumentError, TypeError
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
67
77
|
def parse_raw_value_as_a_number(raw_value)
|
78
|
+
return raw_value.to_i if is_integer?(raw_value)
|
68
79
|
Kernel.Float(raw_value) if raw_value !~ /\A0[xX]/
|
69
|
-
rescue ArgumentError, TypeError
|
70
|
-
nil
|
71
80
|
end
|
72
81
|
|
73
|
-
def
|
74
|
-
|
82
|
+
def is_integer?(raw_value)
|
83
|
+
/\A[+-]?\d+\z/ === raw_value.to_s
|
75
84
|
end
|
76
85
|
|
77
86
|
def filtered_options(value)
|
@@ -115,7 +115,7 @@ module ActiveModel
|
|
115
115
|
key = "#{key.to_s.camelize}Validator"
|
116
116
|
|
117
117
|
begin
|
118
|
-
validator = key.include?('::') ? key.constantize : const_get(key)
|
118
|
+
validator = key.include?('::'.freeze) ? key.constantize : const_get(key)
|
119
119
|
rescue NameError
|
120
120
|
raise ArgumentError, "Unknown validator: '#{key}'"
|
121
121
|
end
|
@@ -1,15 +1,5 @@
|
|
1
1
|
module ActiveModel
|
2
2
|
module Validations
|
3
|
-
module HelperMethods
|
4
|
-
private
|
5
|
-
def _merge_attributes(attr_names)
|
6
|
-
options = attr_names.extract_options!.symbolize_keys
|
7
|
-
attr_names.flatten!
|
8
|
-
options[:attributes] = attr_names
|
9
|
-
options
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
class WithValidator < EachValidator # :nodoc:
|
14
4
|
def validate_each(record, attr, val)
|
15
5
|
method_name = options[:with]
|
@@ -163,7 +163,7 @@ module ActiveModel
|
|
163
163
|
options = options.dup
|
164
164
|
options[:if] = Array(options[:if])
|
165
165
|
options[:if].unshift ->(o) {
|
166
|
-
Array(options[:on])
|
166
|
+
!(Array(options[:on]) & Array(o.validation_context)).empty?
|
167
167
|
}
|
168
168
|
end
|
169
169
|
|
@@ -375,6 +375,15 @@ module ActiveModel
|
|
375
375
|
!valid?(context)
|
376
376
|
end
|
377
377
|
|
378
|
+
# Runs all the validations within the specified context. Returns +true+ if
|
379
|
+
# no errors are found, raises +ValidationError+ otherwise.
|
380
|
+
#
|
381
|
+
# Validations with no <tt>:on</tt> option will run no matter the context. Validations with
|
382
|
+
# some <tt>:on</tt> option will only run in the specified context.
|
383
|
+
def validate!(context = nil)
|
384
|
+
valid?(context) || raise_validation_error
|
385
|
+
end
|
386
|
+
|
378
387
|
# Hook method defining how an attribute value should be retrieved. By default
|
379
388
|
# this is assumed to be an instance named after the attribute. Override this
|
380
389
|
# method in subclasses should you need to retrieve the value for a given
|
@@ -399,6 +408,30 @@ module ActiveModel
|
|
399
408
|
_run_validate_callbacks
|
400
409
|
errors.empty?
|
401
410
|
end
|
411
|
+
|
412
|
+
def raise_validation_error
|
413
|
+
raise(ValidationError.new(self))
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
# = Active Model ValidationError
|
418
|
+
#
|
419
|
+
# Raised by <tt>validate!</tt> when the model is invalid. Use the
|
420
|
+
# +model+ method to retrieve the record which did not validate.
|
421
|
+
#
|
422
|
+
# begin
|
423
|
+
# complex_operation_that_internally_calls_validate!
|
424
|
+
# rescue ActiveModel::ValidationError => invalid
|
425
|
+
# puts invalid.model.errors
|
426
|
+
# end
|
427
|
+
class ValidationError < StandardError
|
428
|
+
attr_reader :model
|
429
|
+
|
430
|
+
def initialize(model)
|
431
|
+
@model = model
|
432
|
+
errors = @model.errors.full_messages.join(", ")
|
433
|
+
super(I18n.t(:"#{@model.class.i18n_scope}.errors.messages.model_invalid", errors: errors, default: :"errors.messages.model_invalid"))
|
434
|
+
end
|
402
435
|
end
|
403
436
|
end
|
404
437
|
|
@@ -15,7 +15,7 @@ module ActiveModel
|
|
15
15
|
# class MyValidator < ActiveModel::Validator
|
16
16
|
# def validate(record)
|
17
17
|
# if some_complex_logic
|
18
|
-
# record.errors
|
18
|
+
# record.errors.add(:base, "This record is invalid")
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
#
|
@@ -100,7 +100,7 @@ module ActiveModel
|
|
100
100
|
# PresenceValidator.kind # => :presence
|
101
101
|
# UniquenessValidator.kind # => :uniqueness
|
102
102
|
def self.kind
|
103
|
-
@kind ||= name.split('::').last.underscore.
|
103
|
+
@kind ||= name.split('::').last.underscore.chomp('_validator').to_sym unless anonymous?
|
104
104
|
end
|
105
105
|
|
106
106
|
# Accepts options that will be made available through the +options+ reader.
|
@@ -127,7 +127,7 @@ module ActiveModel
|
|
127
127
|
# in the options hash invoking the <tt>validate_each</tt> method passing in the
|
128
128
|
# record, attribute and value.
|
129
129
|
#
|
130
|
-
# All Active Model validations are built on top of this validator.
|
130
|
+
# All \Active \Model validations are built on top of this validator.
|
131
131
|
class EachValidator < Validator #:nodoc:
|
132
132
|
attr_reader :attributes
|
133
133
|
|
@@ -142,8 +142,8 @@ module ActiveModel
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# Performs validation on the supplied record. By default this will call
|
145
|
-
# +
|
146
|
-
# override +
|
145
|
+
# +validate_each+ to determine validity therefore subclasses should
|
146
|
+
# override +validate_each+ with validation logic.
|
147
147
|
def validate(record)
|
148
148
|
attributes.each do |attribute|
|
149
149
|
value = record.read_attribute_for_validation(attribute)
|
data/lib/active_model/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative 'gem_version'
|
2
2
|
|
3
3
|
module ActiveModel
|
4
|
-
# Returns the version of the currently loaded
|
4
|
+
# Returns the version of the currently loaded \Active \Model as a <tt>Gem::Version</tt>
|
5
5
|
def self.version
|
6
6
|
gem_version
|
7
7
|
end
|
data/lib/active_model.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2004-
|
2
|
+
# Copyright (c) 2004-2016 David Heinemeier Hansson
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -28,6 +28,7 @@ require 'active_model/version'
|
|
28
28
|
module ActiveModel
|
29
29
|
extend ActiveSupport::Autoload
|
30
30
|
|
31
|
+
autoload :AttributeAssignment
|
31
32
|
autoload :AttributeMethods
|
32
33
|
autoload :BlockValidator, 'active_model/validator'
|
33
34
|
autoload :Callbacks
|
@@ -48,7 +49,9 @@ module ActiveModel
|
|
48
49
|
|
49
50
|
eager_autoload do
|
50
51
|
autoload :Errors
|
52
|
+
autoload :RangeError, 'active_model/errors'
|
51
53
|
autoload :StrictValidationFailed, 'active_model/errors'
|
54
|
+
autoload :UnknownAttributeError, 'active_model/errors'
|
52
55
|
end
|
53
56
|
|
54
57
|
module Serializers
|
@@ -56,7 +59,6 @@ module ActiveModel
|
|
56
59
|
|
57
60
|
eager_autoload do
|
58
61
|
autoload :JSON
|
59
|
-
autoload :Xml
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.7.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: builder
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.1'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.1'
|
26
|
+
version: 5.0.7.2
|
41
27
|
description: A toolkit for building modeling frameworks like Active Record. Rich support
|
42
28
|
for attributes, callbacks, validations, serialization, internationalization, and
|
43
29
|
testing.
|
@@ -50,6 +36,7 @@ files:
|
|
50
36
|
- MIT-LICENSE
|
51
37
|
- README.rdoc
|
52
38
|
- lib/active_model.rb
|
39
|
+
- lib/active_model/attribute_assignment.rb
|
53
40
|
- lib/active_model/attribute_methods.rb
|
54
41
|
- lib/active_model/callbacks.rb
|
55
42
|
- lib/active_model/conversion.rb
|
@@ -65,9 +52,30 @@ files:
|
|
65
52
|
- lib/active_model/secure_password.rb
|
66
53
|
- lib/active_model/serialization.rb
|
67
54
|
- lib/active_model/serializers/json.rb
|
68
|
-
- lib/active_model/serializers/xml.rb
|
69
55
|
- lib/active_model/test_case.rb
|
70
56
|
- lib/active_model/translation.rb
|
57
|
+
- lib/active_model/type.rb
|
58
|
+
- lib/active_model/type/big_integer.rb
|
59
|
+
- lib/active_model/type/binary.rb
|
60
|
+
- lib/active_model/type/boolean.rb
|
61
|
+
- lib/active_model/type/date.rb
|
62
|
+
- lib/active_model/type/date_time.rb
|
63
|
+
- lib/active_model/type/decimal.rb
|
64
|
+
- lib/active_model/type/decimal_without_scale.rb
|
65
|
+
- lib/active_model/type/float.rb
|
66
|
+
- lib/active_model/type/helpers.rb
|
67
|
+
- lib/active_model/type/helpers/accepts_multiparameter_time.rb
|
68
|
+
- lib/active_model/type/helpers/mutable.rb
|
69
|
+
- lib/active_model/type/helpers/numeric.rb
|
70
|
+
- lib/active_model/type/helpers/time_value.rb
|
71
|
+
- lib/active_model/type/immutable_string.rb
|
72
|
+
- lib/active_model/type/integer.rb
|
73
|
+
- lib/active_model/type/registry.rb
|
74
|
+
- lib/active_model/type/string.rb
|
75
|
+
- lib/active_model/type/text.rb
|
76
|
+
- lib/active_model/type/time.rb
|
77
|
+
- lib/active_model/type/unsigned_integer.rb
|
78
|
+
- lib/active_model/type/value.rb
|
71
79
|
- lib/active_model/validations.rb
|
72
80
|
- lib/active_model/validations/absence.rb
|
73
81
|
- lib/active_model/validations/acceptance.rb
|
@@ -76,6 +84,7 @@ files:
|
|
76
84
|
- lib/active_model/validations/confirmation.rb
|
77
85
|
- lib/active_model/validations/exclusion.rb
|
78
86
|
- lib/active_model/validations/format.rb
|
87
|
+
- lib/active_model/validations/helper_methods.rb
|
79
88
|
- lib/active_model/validations/inclusion.rb
|
80
89
|
- lib/active_model/validations/length.rb
|
81
90
|
- lib/active_model/validations/numericality.rb
|
@@ -84,7 +93,7 @@ files:
|
|
84
93
|
- lib/active_model/validations/with.rb
|
85
94
|
- lib/active_model/validator.rb
|
86
95
|
- lib/active_model/version.rb
|
87
|
-
homepage: http://
|
96
|
+
homepage: http://rubyonrails.org
|
88
97
|
licenses:
|
89
98
|
- MIT
|
90
99
|
metadata: {}
|
@@ -96,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
105
|
requirements:
|
97
106
|
- - ">="
|
98
107
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
108
|
+
version: 2.2.2
|
100
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
110
|
requirements:
|
102
111
|
- - ">="
|
103
112
|
- !ruby/object:Gem::Version
|
104
113
|
version: '0'
|
105
114
|
requirements: []
|
106
|
-
rubygems_version: 3.0.
|
115
|
+
rubygems_version: 3.0.1
|
107
116
|
signing_key:
|
108
117
|
specification_version: 4
|
109
118
|
summary: A toolkit for building modeling frameworks (part of Rails).
|