activemodel 7.0.2.3 → 7.0.4
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 +36 -0
- data/lib/active_model/api.rb +1 -1
- data/lib/active_model/attribute_methods.rb +3 -2
- data/lib/active_model/callbacks.rb +2 -2
- data/lib/active_model/error.rb +2 -2
- data/lib/active_model/errors.rb +20 -13
- data/lib/active_model/gem_version.rb +3 -3
- data/lib/active_model/model.rb +2 -2
- data/lib/active_model/secure_password.rb +24 -1
- data/lib/active_model/serialization.rb +5 -6
- data/lib/active_model/translation.rb +1 -1
- data/lib/active_model/validations/absence.rb +1 -1
- data/lib/active_model/validations/acceptance.rb +1 -1
- data/lib/active_model/validations/callbacks.rb +1 -1
- data/lib/active_model/validations/comparison.rb +1 -1
- data/lib/active_model/validations/confirmation.rb +1 -1
- data/lib/active_model/validations/exclusion.rb +3 -3
- data/lib/active_model/validations/format.rb +1 -1
- data/lib/active_model/validations/inclusion.rb +3 -3
- data/lib/active_model/validations/length.rb +2 -2
- data/lib/active_model/validations/numericality.rb +1 -1
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/validates.rb +3 -3
- data/lib/active_model/validations/with.rb +4 -4
- data/lib/active_model/validations.rb +8 -8
- data/lib/active_model/validator.rb +3 -3
- data/lib/active_model/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 630260cc44166916794fb7e43002e72a303ff43b834e82e530cff1f13f25ee7f
|
4
|
+
data.tar.gz: f136cec57987c03ab4aa3fba2b65fe2964b010a326e28cdc0d32f755b45612f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b16a3dd6f96bf2ec1bfa5e3abba2e513567b12035e34e8ea30c24fb8a08ca70089d394f5daa0f40fdc4e14fb63470593904a5a335f864782983c719cf0d57d2
|
7
|
+
data.tar.gz: 66f3f86fcf4b90ffbab8ea82777ac2df48f1774f7ff528d44ec81e12ea47cb2050309b5535e9e960757eb8f9350efa9c6a128754c3b117fdedef3e3c42a43765
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
## Rails 7.0.4 (September 09, 2022) ##
|
2
|
+
|
3
|
+
* Handle name clashes in attribute methods code generation cache.
|
4
|
+
|
5
|
+
When two distinct attribute methods would generate similar names,
|
6
|
+
the first implementation would be incorrectly re-used.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
class A
|
10
|
+
attribute_method_suffix "_changed?"
|
11
|
+
define_attribute_methods :x
|
12
|
+
end
|
13
|
+
|
14
|
+
class B
|
15
|
+
attribute_method_suffix "?"
|
16
|
+
define_attribute_methods :x_changed
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
*Jean Boussier*
|
21
|
+
|
22
|
+
## Rails 7.0.3.1 (July 12, 2022) ##
|
23
|
+
|
24
|
+
* No changes.
|
25
|
+
|
26
|
+
|
27
|
+
## Rails 7.0.3 (May 09, 2022) ##
|
28
|
+
|
29
|
+
* No changes.
|
30
|
+
|
31
|
+
|
32
|
+
## Rails 7.0.2.4 (April 26, 2022) ##
|
33
|
+
|
34
|
+
* No changes.
|
35
|
+
|
36
|
+
|
1
37
|
## Rails 7.0.2.3 (March 08, 2022) ##
|
2
38
|
|
3
39
|
* No changes.
|
data/lib/active_model/api.rb
CHANGED
@@ -5,7 +5,7 @@ module ActiveModel
|
|
5
5
|
#
|
6
6
|
# Includes the required interface for an object to interact with
|
7
7
|
# Action Pack and Action View, using different Active Model modules.
|
8
|
-
# It includes model name introspections, conversions, translations and
|
8
|
+
# It includes model name introspections, conversions, translations, and
|
9
9
|
# validations. Besides that, it allows you to initialize the object with a
|
10
10
|
# hash of attributes, pretty much like Active Record does.
|
11
11
|
#
|
@@ -253,7 +253,7 @@ module ActiveModel
|
|
253
253
|
# <tt>ActiveModel::AttributeMethods</tt>.
|
254
254
|
#
|
255
255
|
# To use, pass attribute names (as strings or symbols). Be sure to declare
|
256
|
-
# +define_attribute_methods+ after you define any prefix, suffix or affix
|
256
|
+
# +define_attribute_methods+ after you define any prefix, suffix, or affix
|
257
257
|
# methods, or they will not hook in.
|
258
258
|
#
|
259
259
|
# class Person
|
@@ -394,7 +394,7 @@ module ActiveModel
|
|
394
394
|
mangled_name = "__temp__#{name.unpack1("h*")}"
|
395
395
|
end
|
396
396
|
|
397
|
-
code_generator.define_cached_method(name, as: mangled_name, namespace: namespace) do |batch|
|
397
|
+
code_generator.define_cached_method(name, as: mangled_name, namespace: :"#{namespace}_#{target}") do |batch|
|
398
398
|
call_args.map!(&:inspect)
|
399
399
|
call_args << parameters if parameters
|
400
400
|
|
@@ -467,6 +467,7 @@ module ActiveModel
|
|
467
467
|
def attribute_missing(match, *args, &block)
|
468
468
|
__send__(match.target, match.attr_name, *args, &block)
|
469
469
|
end
|
470
|
+
ruby2_keywords(:attribute_missing)
|
470
471
|
|
471
472
|
# A +Person+ instance with a +name+ attribute can ask
|
472
473
|
# <tt>person.respond_to?(:name)</tt>, <tt>person.respond_to?(:name=)</tt>,
|
@@ -32,7 +32,7 @@ module ActiveModel
|
|
32
32
|
# end
|
33
33
|
# end
|
34
34
|
#
|
35
|
-
# Then in your class, you can use the +before_create+, +after_create
|
35
|
+
# Then in your class, you can use the +before_create+, +after_create+, and
|
36
36
|
# +around_create+ methods, just as you would in an Active Record model.
|
37
37
|
#
|
38
38
|
# before_create :action_before_create
|
@@ -84,7 +84,7 @@ module ActiveModel
|
|
84
84
|
# define_model_callbacks :update, only: :before
|
85
85
|
# define_model_callbacks :destroy, only: :around
|
86
86
|
#
|
87
|
-
# Would create +after_create+, +before_update
|
87
|
+
# Would create +after_create+, +before_update+, and +around_destroy+ methods
|
88
88
|
# only.
|
89
89
|
#
|
90
90
|
# You can pass in a class to before_<type>, after_<type> and around_<type>,
|
data/lib/active_model/error.rb
CHANGED
@@ -159,7 +159,7 @@ module ActiveModel
|
|
159
159
|
self.class.full_message(attribute, message, @base)
|
160
160
|
end
|
161
161
|
|
162
|
-
# See if error matches provided +attribute+, +type
|
162
|
+
# See if error matches provided +attribute+, +type+, and +options+.
|
163
163
|
#
|
164
164
|
# Omitted params are not checked for a match.
|
165
165
|
def match?(attribute, type = nil, **options)
|
@@ -176,7 +176,7 @@ module ActiveModel
|
|
176
176
|
true
|
177
177
|
end
|
178
178
|
|
179
|
-
# See if error matches provided +attribute+, +type
|
179
|
+
# See if error matches provided +attribute+, +type+, and +options+ exactly.
|
180
180
|
#
|
181
181
|
# All params must be equal to Error's own attributes to be considered a
|
182
182
|
# strict match.
|
data/lib/active_model/errors.rb
CHANGED
@@ -48,9 +48,9 @@ module ActiveModel
|
|
48
48
|
#
|
49
49
|
# The last three methods are required in your object for +Errors+ to be
|
50
50
|
# able to generate error messages correctly and also handle multiple
|
51
|
-
# languages. Of course, if you extend your object with
|
51
|
+
# languages. Of course, if you extend your object with ActiveModel::Translation
|
52
52
|
# you will not need to implement the last two. Likewise, using
|
53
|
-
#
|
53
|
+
# ActiveModel::Validations will handle the validation related methods
|
54
54
|
# for you.
|
55
55
|
#
|
56
56
|
# The above allows you to do:
|
@@ -102,11 +102,14 @@ module ActiveModel
|
|
102
102
|
# Copies the errors from <tt>other</tt>.
|
103
103
|
# For copying errors but keep <tt>@base</tt> as is.
|
104
104
|
#
|
105
|
-
#
|
105
|
+
# ==== Parameters
|
106
106
|
#
|
107
|
-
#
|
107
|
+
# * +other+ - The ActiveModel::Errors instance.
|
108
|
+
#
|
109
|
+
# ==== Examples
|
108
110
|
#
|
109
111
|
# person.errors.copy!(other)
|
112
|
+
#
|
110
113
|
def copy!(other) # :nodoc:
|
111
114
|
@errors = other.errors.deep_dup
|
112
115
|
@errors.each { |error|
|
@@ -114,14 +117,15 @@ module ActiveModel
|
|
114
117
|
}
|
115
118
|
end
|
116
119
|
|
117
|
-
# Imports one error
|
120
|
+
# Imports one error.
|
118
121
|
# Imported errors are wrapped as a NestedError,
|
119
122
|
# providing access to original error object.
|
120
123
|
# If attribute or type needs to be overridden, use +override_options+.
|
121
124
|
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
+
# ==== Options
|
126
|
+
#
|
127
|
+
# * +:attribute+ - Override the attribute the error belongs to.
|
128
|
+
# * +:type+ - Override type of the error.
|
125
129
|
def import(error, override_options = {})
|
126
130
|
[:attribute, :type].each do |key|
|
127
131
|
if override_options.key?(key)
|
@@ -132,13 +136,16 @@ module ActiveModel
|
|
132
136
|
end
|
133
137
|
|
134
138
|
# Merges the errors from <tt>other</tt>,
|
135
|
-
# each
|
139
|
+
# each Error wrapped as NestedError.
|
136
140
|
#
|
137
|
-
#
|
141
|
+
# ==== Parameters
|
138
142
|
#
|
139
|
-
#
|
143
|
+
# * +other+ - The ActiveModel::Errors instance.
|
144
|
+
#
|
145
|
+
# ==== Examples
|
140
146
|
#
|
141
147
|
# person.errors.merge!(other)
|
148
|
+
#
|
142
149
|
def merge!(other)
|
143
150
|
return errors if equal?(other)
|
144
151
|
|
@@ -147,7 +154,7 @@ module ActiveModel
|
|
147
154
|
}
|
148
155
|
end
|
149
156
|
|
150
|
-
# Search for errors matching +attribute+, +type
|
157
|
+
# Search for errors matching +attribute+, +type+, or +options+.
|
151
158
|
#
|
152
159
|
# Only supplied params will be matched.
|
153
160
|
#
|
@@ -427,7 +434,7 @@ module ActiveModel
|
|
427
434
|
# if it's not there, it's looked up in <tt>activemodel.errors.models.MODEL.MESSAGE</tt> and if
|
428
435
|
# that is not there also, it returns the translation of the default message
|
429
436
|
# (e.g. <tt>activemodel.errors.messages.MESSAGE</tt>). The translated model
|
430
|
-
# name, translated attribute name and the value are available for
|
437
|
+
# name, translated attribute name, and the value are available for
|
431
438
|
# interpolation.
|
432
439
|
#
|
433
440
|
# When using inheritance in your models, it will check all the inherited
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveModel
|
4
|
-
# Returns the version of
|
4
|
+
# Returns the currently loaded version of \Active \Model as a <tt>Gem::Version</tt>.
|
5
5
|
def self.gem_version
|
6
6
|
Gem::Version.new VERSION::STRING
|
7
7
|
end
|
@@ -9,8 +9,8 @@ module ActiveModel
|
|
9
9
|
module VERSION
|
10
10
|
MAJOR = 7
|
11
11
|
MINOR = 0
|
12
|
-
TINY =
|
13
|
-
PRE =
|
12
|
+
TINY = 4
|
13
|
+
PRE = nil
|
14
14
|
|
15
15
|
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
16
16
|
end
|
data/lib/active_model/model.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
module ActiveModel
|
4
4
|
# == Active \Model \Basic \Model
|
5
5
|
#
|
6
|
-
# Allows implementing models similar to
|
7
|
-
# Includes
|
6
|
+
# Allows implementing models similar to ActiveRecord::Base.
|
7
|
+
# Includes ActiveModel::API for the required interface for an
|
8
8
|
# object to interact with Action Pack and Action View, but can be
|
9
9
|
# extended with other functionalities.
|
10
10
|
#
|
@@ -36,7 +36,9 @@ module ActiveModel
|
|
36
36
|
#
|
37
37
|
# gem 'bcrypt', '~> 3.1.7'
|
38
38
|
#
|
39
|
-
#
|
39
|
+
# ==== Examples
|
40
|
+
#
|
41
|
+
# ===== Using Active Record (which automatically includes ActiveModel::SecurePassword)
|
40
42
|
#
|
41
43
|
# # Schema: User(name:string, password_digest:string, recovery_password_digest:string)
|
42
44
|
# class User < ActiveRecord::Base
|
@@ -58,6 +60,27 @@ module ActiveModel
|
|
58
60
|
# user.authenticate_recovery_password('42password') # => user
|
59
61
|
# User.find_by(name: 'david')&.authenticate('notright') # => false
|
60
62
|
# User.find_by(name: 'david')&.authenticate('mUc3m00RsqyRe') # => user
|
63
|
+
#
|
64
|
+
# ===== Conditionally requiring a password
|
65
|
+
#
|
66
|
+
# class Account
|
67
|
+
# include ActiveModel::SecurePassword
|
68
|
+
#
|
69
|
+
# attr_accessor :is_guest, :password_digest
|
70
|
+
#
|
71
|
+
# has_secure_password
|
72
|
+
#
|
73
|
+
# def errors
|
74
|
+
# super.tap { |errors| errors.delete(:password, :blank) if is_guest }
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# account = Account.new
|
79
|
+
# account.valid? # => false, password required
|
80
|
+
#
|
81
|
+
# account.is_guest = true
|
82
|
+
# account.valid? # => true
|
83
|
+
#
|
61
84
|
def has_secure_password(attribute = :password, validations: true)
|
62
85
|
# Load bcrypt gem only when has_secure_password is used.
|
63
86
|
# This is to avoid ActiveModel (and by extension the entire framework)
|
@@ -123,7 +123,7 @@ module ActiveModel
|
|
123
123
|
# user.serializable_hash(include: { notes: { only: 'title' }})
|
124
124
|
# # => {"name" => "Napoleon", "notes" => [{"title"=>"Battle of Austerlitz"}]}
|
125
125
|
def serializable_hash(options = nil)
|
126
|
-
attribute_names =
|
126
|
+
attribute_names = attribute_names_for_serialization
|
127
127
|
|
128
128
|
return serializable_attributes(attribute_names) if options.blank?
|
129
129
|
|
@@ -148,12 +148,11 @@ module ActiveModel
|
|
148
148
|
hash
|
149
149
|
end
|
150
150
|
|
151
|
-
# Returns an array of attribute names as strings
|
152
|
-
def attribute_names # :nodoc:
|
153
|
-
attributes.keys
|
154
|
-
end
|
155
|
-
|
156
151
|
private
|
152
|
+
def attribute_names_for_serialization
|
153
|
+
attributes.keys
|
154
|
+
end
|
155
|
+
|
157
156
|
# Hook method defining how an attribute value should be retrieved for
|
158
157
|
# serialization. By default this is assumed to be an instance named after
|
159
158
|
# the attribute. Override this method in subclasses should you need to
|
@@ -22,7 +22,7 @@ module ActiveModel
|
|
22
22
|
module Translation
|
23
23
|
include ActiveModel::Naming
|
24
24
|
|
25
|
-
# Returns the +i18n_scope+ for the class.
|
25
|
+
# Returns the +i18n_scope+ for the class. Override if you want custom lookup.
|
26
26
|
def i18n_scope
|
27
27
|
:activemodel
|
28
28
|
end
|
@@ -24,7 +24,7 @@ module ActiveModel
|
|
24
24
|
#
|
25
25
|
# There is also a list of default options supported by every validator:
|
26
26
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
27
|
-
# See
|
27
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
28
28
|
def validates_absence_of(*attr_names)
|
29
29
|
validates_with AbsenceValidator, _merge_attributes(attr_names)
|
30
30
|
end
|
@@ -104,7 +104,7 @@ module ActiveModel
|
|
104
104
|
#
|
105
105
|
# There is also a list of default options supported by every validator:
|
106
106
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
107
|
-
# See
|
107
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
108
108
|
def validates_acceptance_of(*attr_names)
|
109
109
|
validates_with AcceptanceValidator, _merge_attributes(attr_names)
|
110
110
|
end
|
@@ -56,7 +56,7 @@ module ActiveModel
|
|
56
56
|
#
|
57
57
|
# There is also a list of default options supported by every validator:
|
58
58
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
|
59
|
-
# See
|
59
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
60
60
|
#
|
61
61
|
# The validator requires at least one of the following checks to be supplied.
|
62
62
|
# Each will accept a proc, value, or a symbol which corresponds to a method:
|
@@ -71,7 +71,7 @@ module ActiveModel
|
|
71
71
|
#
|
72
72
|
# There is also a list of default options supported by every validator:
|
73
73
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
74
|
-
# See
|
74
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
75
75
|
def validates_confirmation_of(*attr_names)
|
76
76
|
validates_with ConfirmationValidator, _merge_attributes(attr_names)
|
77
77
|
end
|
@@ -29,8 +29,8 @@ module ActiveModel
|
|
29
29
|
#
|
30
30
|
# Configuration options:
|
31
31
|
# * <tt>:in</tt> - An enumerable object of items that the value shouldn't
|
32
|
-
# be part of. This can be supplied as a proc, lambda or symbol which returns an
|
33
|
-
# enumerable. If the enumerable is a numerical, time or datetime range the test
|
32
|
+
# be part of. This can be supplied as a proc, lambda, or symbol which returns an
|
33
|
+
# enumerable. If the enumerable is a numerical, time, or datetime range the test
|
34
34
|
# is performed with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When
|
35
35
|
# using a proc or lambda the instance under validation is passed as an argument.
|
36
36
|
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
@@ -40,7 +40,7 @@ module ActiveModel
|
|
40
40
|
#
|
41
41
|
# There is also a list of default options supported by every validator:
|
42
42
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
43
|
-
# See
|
43
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
44
44
|
def validates_exclusion_of(*attr_names)
|
45
45
|
validates_with ExclusionValidator, _merge_attributes(attr_names)
|
46
46
|
end
|
@@ -104,7 +104,7 @@ module ActiveModel
|
|
104
104
|
#
|
105
105
|
# There is also a list of default options supported by every validator:
|
106
106
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
107
|
-
# See
|
107
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
108
108
|
def validates_format_of(*attr_names)
|
109
109
|
validates_with FormatValidator, _merge_attributes(attr_names)
|
110
110
|
end
|
@@ -28,8 +28,8 @@ module ActiveModel
|
|
28
28
|
#
|
29
29
|
# Configuration options:
|
30
30
|
# * <tt>:in</tt> - An enumerable object of available items. This can be
|
31
|
-
# supplied as a proc, lambda or symbol which returns an enumerable. If the
|
32
|
-
# enumerable is a numerical, time or datetime range the test is performed
|
31
|
+
# supplied as a proc, lambda, or symbol which returns an enumerable. If the
|
32
|
+
# enumerable is a numerical, time, or datetime range the test is performed
|
33
33
|
# with <tt>Range#cover?</tt>, otherwise with <tt>include?</tt>. When using
|
34
34
|
# a proc or lambda the instance under validation is passed as an argument.
|
35
35
|
# * <tt>:within</tt> - A synonym(or alias) for <tt>:in</tt>
|
@@ -38,7 +38,7 @@ module ActiveModel
|
|
38
38
|
#
|
39
39
|
# There is also a list of default options supported by every validator:
|
40
40
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
41
|
-
# See
|
41
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
42
42
|
def validates_inclusion_of(*attr_names)
|
43
43
|
validates_with InclusionValidator, _merge_attributes(attr_names)
|
44
44
|
end
|
@@ -117,8 +117,8 @@ module ActiveModel
|
|
117
117
|
# <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
|
118
118
|
#
|
119
119
|
# There is also a list of default options supported by every validator:
|
120
|
-
# +:if+, +:unless+, +:on
|
121
|
-
# See
|
120
|
+
# +:if+, +:unless+, +:on+, and +:strict+.
|
121
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
122
122
|
def validates_length_of(*attr_names)
|
123
123
|
validates_with LengthValidator, _merge_attributes(attr_names)
|
124
124
|
end
|
@@ -183,7 +183,7 @@ module ActiveModel
|
|
183
183
|
#
|
184
184
|
# There is also a list of default options supported by every validator:
|
185
185
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+ .
|
186
|
-
# See
|
186
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
187
187
|
#
|
188
188
|
# The following checks can also be supplied with a proc or a symbol which
|
189
189
|
# corresponds to a method:
|
@@ -30,7 +30,7 @@ module ActiveModel
|
|
30
30
|
#
|
31
31
|
# There is also a list of default options supported by every validator:
|
32
32
|
# +:if+, +:unless+, +:on+, +:allow_nil+, +:allow_blank+, and +:strict+.
|
33
|
-
# See
|
33
|
+
# See ActiveModel::Validations::ClassMethods#validates for more information.
|
34
34
|
def validates_presence_of(*attr_names)
|
35
35
|
validates_with PresenceValidator, _merge_attributes(attr_names)
|
36
36
|
end
|
@@ -78,14 +78,14 @@ module ActiveModel
|
|
78
78
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
79
79
|
# <tt>on: :custom_validation_context</tt> or
|
80
80
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
81
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
81
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
82
82
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
83
83
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
84
84
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
85
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine
|
85
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to determine
|
86
86
|
# if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
87
87
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
88
|
-
# method, proc or string should return or evaluate to a +true+ or
|
88
|
+
# method, proc, or string should return or evaluate to a +true+ or
|
89
89
|
# +false+ value.
|
90
90
|
# * <tt>:allow_nil</tt> - Skip validation if the attribute is +nil+.
|
91
91
|
# * <tt>:allow_blank</tt> - Skip validation if the attribute is blank.
|
@@ -51,16 +51,16 @@ module ActiveModel
|
|
51
51
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
52
52
|
# <tt>on: :custom_validation_context</tt> or
|
53
53
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
54
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
54
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
55
55
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
56
56
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>).
|
57
|
-
# The method, proc or string should return or evaluate to a +true+ or
|
57
|
+
# The method, proc, or string should return or evaluate to a +true+ or
|
58
58
|
# +false+ value.
|
59
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
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
|
-
# The method, proc or string should return or evaluate to a +true+ or
|
63
|
+
# The method, proc, or string should return or evaluate to a +true+ or
|
64
64
|
# +false+ value.
|
65
65
|
# * <tt>:strict</tt> - Specifies whether validation should be strict.
|
66
66
|
# See <tt>ActiveModel::Validations#validates!</tt> for more information.
|
@@ -32,7 +32,7 @@ module ActiveModel
|
|
32
32
|
# person.errors.messages # => {first_name:["starts with z."]}
|
33
33
|
#
|
34
34
|
# Note that <tt>ActiveModel::Validations</tt> automatically adds an +errors+
|
35
|
-
# method to your instances initialized with a new
|
35
|
+
# method to your instances initialized with a new ActiveModel::Errors
|
36
36
|
# object, so there is no need for you to do this manually.
|
37
37
|
module Validations
|
38
38
|
extend ActiveSupport::Concern
|
@@ -73,14 +73,14 @@ module ActiveModel
|
|
73
73
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
74
74
|
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
|
75
75
|
# * <tt>:allow_blank</tt> - Skip validation if attribute is blank.
|
76
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
76
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
77
77
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
78
78
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
79
79
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
80
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
80
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to
|
81
81
|
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
82
82
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
83
|
-
# method, proc or string should return or evaluate to a +true+ or +false+
|
83
|
+
# method, proc, or string should return or evaluate to a +true+ or +false+
|
84
84
|
# value.
|
85
85
|
def validates_each(*attr_names, &block)
|
86
86
|
validates_with BlockValidator, _merge_attributes(attr_names), &block
|
@@ -137,14 +137,14 @@ module ActiveModel
|
|
137
137
|
# or an array of symbols. (e.g. <tt>on: :create</tt> or
|
138
138
|
# <tt>on: :custom_validation_context</tt> or
|
139
139
|
# <tt>on: [:create, :custom_validation_context]</tt>)
|
140
|
-
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
|
140
|
+
# * <tt>:if</tt> - Specifies a method, proc, or string to call to determine
|
141
141
|
# if the validation should occur (e.g. <tt>if: :allow_validation</tt>,
|
142
142
|
# or <tt>if: Proc.new { |user| user.signup_step > 2 }</tt>). The method,
|
143
143
|
# proc or string should return or evaluate to a +true+ or +false+ value.
|
144
|
-
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
|
144
|
+
# * <tt>:unless</tt> - Specifies a method, proc, or string to call to
|
145
145
|
# determine if the validation should not occur (e.g. <tt>unless: :skip_validation</tt>,
|
146
146
|
# or <tt>unless: Proc.new { |user| user.signup_step <= 2 }</tt>). The
|
147
|
-
# method, proc or string should return or evaluate to a +true+ or +false+
|
147
|
+
# method, proc, or string should return or evaluate to a +true+ or +false+
|
148
148
|
# value.
|
149
149
|
#
|
150
150
|
# NOTE: Calling +validate+ multiple times on the same method will overwrite previous definitions.
|
@@ -241,7 +241,7 @@ module ActiveModel
|
|
241
241
|
# class Person
|
242
242
|
# include ActiveModel::Validations
|
243
243
|
#
|
244
|
-
# attr_accessor :name
|
244
|
+
# attr_accessor :name, :age
|
245
245
|
#
|
246
246
|
# validates_presence_of :name
|
247
247
|
# validates_inclusion_of :age, in: 0..99
|
@@ -65,7 +65,7 @@ module ActiveModel
|
|
65
65
|
# life cycle, and not on each validation run.
|
66
66
|
#
|
67
67
|
# The easiest way to add custom validators for validating individual attributes
|
68
|
-
# is with the convenient
|
68
|
+
# is with the convenient ActiveModel::EachValidator.
|
69
69
|
#
|
70
70
|
# class TitleValidator < ActiveModel::EachValidator
|
71
71
|
# def validate_each(record, attribute, value)
|
@@ -74,7 +74,7 @@ module ActiveModel
|
|
74
74
|
# end
|
75
75
|
#
|
76
76
|
# This can now be used in combination with the +validates+ method
|
77
|
-
# (see
|
77
|
+
# (see ActiveModel::Validations::ClassMethods#validates for more on this).
|
78
78
|
#
|
79
79
|
# class Person
|
80
80
|
# include ActiveModel::Validations
|
@@ -126,7 +126,7 @@ module ActiveModel
|
|
126
126
|
|
127
127
|
# +EachValidator+ is a validator which iterates through the attributes given
|
128
128
|
# in the options hash invoking the <tt>validate_each</tt> method passing in the
|
129
|
-
# record, attribute and value.
|
129
|
+
# record, attribute, and value.
|
130
130
|
#
|
131
131
|
# All \Active \Model validations are built on top of this validator.
|
132
132
|
class EachValidator < Validator
|
data/lib/active_model/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative "gem_version"
|
4
4
|
|
5
5
|
module ActiveModel
|
6
|
-
# Returns the version of
|
6
|
+
# Returns the currently loaded version of \Active \Model as a <tt>Gem::Version</tt>.
|
7
7
|
def self.version
|
8
8
|
gem_version
|
9
9
|
end
|
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: 7.0.
|
4
|
+
version: 7.0.4
|
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: 2022-
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.0.
|
19
|
+
version: 7.0.4
|
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: 7.0.
|
26
|
+
version: 7.0.4
|
27
27
|
description: A toolkit for building modeling frameworks like Active Record. Rich support
|
28
28
|
for attributes, callbacks, validations, serialization, internationalization, and
|
29
29
|
testing.
|
@@ -107,10 +107,10 @@ licenses:
|
|
107
107
|
- MIT
|
108
108
|
metadata:
|
109
109
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
110
|
-
changelog_uri: https://github.com/rails/rails/blob/v7.0.
|
111
|
-
documentation_uri: https://api.rubyonrails.org/v7.0.
|
110
|
+
changelog_uri: https://github.com/rails/rails/blob/v7.0.4/activemodel/CHANGELOG.md
|
111
|
+
documentation_uri: https://api.rubyonrails.org/v7.0.4/
|
112
112
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
113
|
-
source_code_uri: https://github.com/rails/rails/tree/v7.0.
|
113
|
+
source_code_uri: https://github.com/rails/rails/tree/v7.0.4/activemodel
|
114
114
|
rubygems_mfa_required: 'true'
|
115
115
|
post_install_message:
|
116
116
|
rdoc_options: []
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.3.3
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: A toolkit for building modeling frameworks (part of Rails).
|