activemodel 6.1.7.6 → 7.0.0
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 +58 -148
- data/MIT-LICENSE +2 -1
- data/README.rdoc +3 -3
- data/lib/active_model/api.rb +99 -0
- data/lib/active_model/attribute.rb +4 -0
- data/lib/active_model/attribute_methods.rb +65 -81
- data/lib/active_model/attribute_set/builder.rb +1 -10
- data/lib/active_model/attribute_set.rb +4 -1
- data/lib/active_model/attributes.rb +15 -12
- data/lib/active_model/callbacks.rb +1 -1
- data/lib/active_model/conversion.rb +2 -2
- data/lib/active_model/dirty.rb +5 -4
- data/lib/active_model/errors.rb +35 -235
- data/lib/active_model/gem_version.rb +4 -4
- data/lib/active_model/locale/en.yml +1 -0
- data/lib/active_model/model.rb +6 -59
- data/lib/active_model/naming.rb +15 -8
- data/lib/active_model/secure_password.rb +1 -1
- data/lib/active_model/serialization.rb +7 -2
- data/lib/active_model/translation.rb +1 -1
- data/lib/active_model/type/date.rb +1 -1
- data/lib/active_model/type/helpers/numeric.rb +9 -1
- data/lib/active_model/type/helpers/time_value.rb +3 -3
- data/lib/active_model/type/integer.rb +4 -1
- data/lib/active_model/type/registry.rb +8 -38
- data/lib/active_model/type/time.rb +1 -1
- data/lib/active_model/type.rb +6 -6
- data/lib/active_model/validations/absence.rb +1 -1
- data/lib/active_model/validations/clusivity.rb +1 -1
- data/lib/active_model/validations/comparability.rb +29 -0
- data/lib/active_model/validations/comparison.rb +82 -0
- data/lib/active_model/validations/confirmation.rb +4 -4
- data/lib/active_model/validations/numericality.rb +28 -21
- data/lib/active_model/validations.rb +4 -4
- data/lib/active_model/validator.rb +2 -2
- data/lib/active_model.rb +2 -1
- metadata +15 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9db6d3afd6b2229e9937481ca1b015819f8d55e0368e1a834177b1f60dd09d8
|
|
4
|
+
data.tar.gz: 3aef39f0ea6189a8fbe7dbb8500deead474df01cbbce41b9eea5629e31cd4e55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f6a49652ed96538b7cea9726a40be7c557b2d4ae95bc87e69b97ab44c057c77482ef0ceaac4f20726506798136825289ffa765a6b89254a8a91f7a8050702b3
|
|
7
|
+
data.tar.gz: c9ea97c715715e8e88e791adf11eadf1588309bbbf1de30be56a81e2991af510c9a30cae24a170ae7f015eda20c5a5617b9ab92a216eabd331deeed39fef7f4e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
|
-
## Rails
|
|
1
|
+
## Rails 7.0.0 (December 15, 2021) ##
|
|
2
2
|
|
|
3
3
|
* No changes.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
## Rails
|
|
6
|
+
## Rails 7.0.0.rc3 (December 14, 2021) ##
|
|
7
7
|
|
|
8
8
|
* No changes.
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
## Rails
|
|
11
|
+
## Rails 7.0.0.rc2 (December 14, 2021) ##
|
|
12
12
|
|
|
13
13
|
* No changes.
|
|
14
14
|
|
|
15
|
+
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
* Remove support to Marshal load Rails 5.x `ActiveModel::AttributeSet` format.
|
|
17
18
|
|
|
18
|
-
*
|
|
19
|
+
*Rafael Mendonça França*
|
|
19
20
|
|
|
21
|
+
* Remove support to Marshal and YAML load Rails 5.x error format.
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
*Rafael Mendonça França*
|
|
22
24
|
|
|
23
|
-
*
|
|
25
|
+
* Remove deprecated support to use `[]=` in `ActiveModel::Errors#messages`.
|
|
24
26
|
|
|
27
|
+
*Rafael Mendonça França*
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
* Remove deprecated support to `delete` errors from `ActiveModel::Errors#messages`.
|
|
27
30
|
|
|
28
|
-
*
|
|
31
|
+
*Rafael Mendonça França*
|
|
29
32
|
|
|
33
|
+
* Remove deprecated support to `clear` errors from `ActiveModel::Errors#messages`.
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
*Rafael Mendonça França*
|
|
32
36
|
|
|
33
|
-
*
|
|
37
|
+
* Remove deprecated support concat errors to `ActiveModel::Errors#messages`.
|
|
34
38
|
|
|
39
|
+
*Rafael Mendonça França*
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
* Remove deprecated `ActiveModel::Errors#to_xml`.
|
|
37
42
|
|
|
38
|
-
*
|
|
43
|
+
*Rafael Mendonça França*
|
|
39
44
|
|
|
45
|
+
* Remove deprecated `ActiveModel::Errors#keys`.
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
*Rafael Mendonça França*
|
|
42
48
|
|
|
43
|
-
*
|
|
49
|
+
* Remove deprecated `ActiveModel::Errors#values`.
|
|
44
50
|
|
|
51
|
+
*Rafael Mendonça França*
|
|
45
52
|
|
|
46
|
-
|
|
53
|
+
* Remove deprecated `ActiveModel::Errors#slice!`.
|
|
47
54
|
|
|
48
|
-
*
|
|
55
|
+
*Rafael Mendonça França*
|
|
56
|
+
|
|
57
|
+
* Remove deprecated `ActiveModel::Errors#to_h`.
|
|
58
|
+
|
|
59
|
+
*Rafael Mendonça França*
|
|
49
60
|
|
|
61
|
+
* Remove deprecated enumeration of `ActiveModel::Errors` instances as a Hash.
|
|
50
62
|
|
|
51
|
-
|
|
63
|
+
*Rafael Mendonça França*
|
|
52
64
|
|
|
53
65
|
* Clear secure password cache if password is set to `nil`
|
|
54
66
|
|
|
@@ -68,165 +80,63 @@
|
|
|
68
80
|
|
|
69
81
|
*Markus Doits*
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Passing a last positional argument `{}` would be incorrectly considered as keyword argument.
|
|
74
|
-
|
|
75
|
-
*Benoit Daloze*
|
|
76
|
-
|
|
77
|
-
* Fix `to_json` after `changes_applied` for `ActiveModel::Dirty` object.
|
|
78
|
-
|
|
79
|
-
*Ryuta Kamizono*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
## Rails 6.1.4.7 (March 08, 2022) ##
|
|
83
|
-
|
|
84
|
-
* No changes.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
## Rails 6.1.4.6 (February 11, 2022) ##
|
|
88
|
-
|
|
89
|
-
* No changes.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
## Rails 6.1.4.5 (February 11, 2022) ##
|
|
93
|
-
|
|
94
|
-
* No changes.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
## Rails 6.1.4.4 (December 15, 2021) ##
|
|
83
|
+
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
|
98
84
|
|
|
99
85
|
* No changes.
|
|
100
86
|
|
|
101
87
|
|
|
102
|
-
## Rails
|
|
88
|
+
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
|
103
89
|
|
|
104
|
-
*
|
|
90
|
+
* Introduce `ActiveModel::API`.
|
|
105
91
|
|
|
92
|
+
Make `ActiveModel::API` the minimum API to talk with Action Pack and Action View.
|
|
93
|
+
This will allow adding more functionality to `ActiveModel::Model`.
|
|
106
94
|
|
|
107
|
-
|
|
95
|
+
*Petrik de Heus*, *Nathaniel Watts*
|
|
108
96
|
|
|
109
|
-
*
|
|
97
|
+
* Fix dirty check for Float::NaN and BigDecimal::NaN.
|
|
110
98
|
|
|
99
|
+
Float::NaN and BigDecimal::NaN in Ruby are [special values](https://bugs.ruby-lang.org/issues/1720)
|
|
100
|
+
and can't be compared with `==`.
|
|
111
101
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* No changes.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
## Rails 6.1.4 (June 24, 2021) ##
|
|
102
|
+
*Marcelo Lauxen*
|
|
118
103
|
|
|
119
104
|
* Fix `to_json` for `ActiveModel::Dirty` object.
|
|
120
105
|
|
|
121
|
-
Exclude
|
|
106
|
+
Exclude `mutations_from_database` attribute from json as it lead to recursion.
|
|
122
107
|
|
|
123
108
|
*Anil Maurya*
|
|
124
109
|
|
|
110
|
+
* Add `ActiveModel::AttributeSet#values_for_database`.
|
|
125
111
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* No changes.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
## Rails 6.1.3.1 (March 26, 2021) ##
|
|
132
|
-
|
|
133
|
-
* No changes.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
## Rails 6.1.3 (February 17, 2021) ##
|
|
137
|
-
|
|
138
|
-
* No changes.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
## Rails 6.1.2.1 (February 10, 2021) ##
|
|
142
|
-
|
|
143
|
-
* No changes.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
## Rails 6.1.2 (February 09, 2021) ##
|
|
147
|
-
|
|
148
|
-
* No changes.
|
|
149
|
-
|
|
112
|
+
Returns attributes with values for assignment to the database.
|
|
150
113
|
|
|
151
|
-
|
|
114
|
+
*Chris Salzberg*
|
|
152
115
|
|
|
153
|
-
*
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
## Rails 6.1.0 (December 09, 2020) ##
|
|
157
|
-
|
|
158
|
-
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
|
159
|
-
|
|
160
|
-
This is useful in cases where the `human_attribute_name` method depends
|
|
161
|
-
on other attributes' values of the class under validation to derive what the
|
|
162
|
-
attribute name should be.
|
|
163
|
-
|
|
164
|
-
*Filipe Sabella*
|
|
165
|
-
|
|
166
|
-
* Deprecate marshalling load from legacy attributes format.
|
|
167
|
-
|
|
168
|
-
*Ryuta Kamizono*
|
|
169
|
-
|
|
170
|
-
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
|
|
116
|
+
* Fix delegation in ActiveModel::Type::Registry#lookup and ActiveModel::Type.lookup.
|
|
171
117
|
|
|
172
|
-
|
|
173
|
-
topic.status_previously_changed?(from: "active", to: "archived")
|
|
174
|
-
# => true
|
|
175
|
-
|
|
176
|
-
*George Claghorn*
|
|
177
|
-
|
|
178
|
-
* Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
|
|
179
|
-
|
|
180
|
-
class Animal
|
|
181
|
-
include ActiveModel::Attributes
|
|
182
|
-
attribute :age
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
animal = Animal.new
|
|
186
|
-
animal.freeze
|
|
187
|
-
animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
|
|
188
|
-
|
|
189
|
-
*Josh Brody*
|
|
190
|
-
|
|
191
|
-
* Add `*_previously_was` attribute methods when dirty tracking. Example:
|
|
118
|
+
Passing a last positional argument `{}` would be incorrectly considered as keyword argument.
|
|
192
119
|
|
|
193
|
-
|
|
194
|
-
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
|
|
195
|
-
pirate.catchphrase_previously_was # => "Thar She Blows!"
|
|
120
|
+
*Benoit Daloze*
|
|
196
121
|
|
|
197
|
-
|
|
122
|
+
* Cache and re-use generated attribute methods.
|
|
198
123
|
|
|
199
|
-
|
|
124
|
+
Generated methods with identical implementations will now share their instruction sequences
|
|
125
|
+
leading to reduced memory retention, and slightly faster load time.
|
|
200
126
|
|
|
201
|
-
|
|
202
|
-
objects, instead of messages/details hash.
|
|
127
|
+
*Jean Boussier*
|
|
203
128
|
|
|
204
|
-
|
|
205
|
-
are for generating error messages. Its `details` method would return error’s
|
|
206
|
-
extra parameters, found in the original `details` hash.
|
|
129
|
+
* Add `in: range` parameter to `numericality` validator.
|
|
207
130
|
|
|
208
|
-
|
|
209
|
-
some edge cases won’t be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
|
|
210
|
-
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
|
|
211
|
-
please convert those direct manipulations to use provided API methods instead.
|
|
212
|
-
Please note that `errors#add` now accepts `options` as keyword arguments instead of `Hash` which
|
|
213
|
-
introduced a change in Ruby 3 to [keyword arguments][kwargs-ann].
|
|
131
|
+
*Michal Papis*
|
|
214
132
|
|
|
215
|
-
|
|
133
|
+
* Add `locale` argument to `ActiveModel::Name#initialize` to be used to generate the `singular`,
|
|
134
|
+
`plural`, `route_key` and `singular_route_key` values.
|
|
216
135
|
|
|
217
|
-
|
|
136
|
+
*Lukas Pokorny*
|
|
218
137
|
|
|
219
|
-
|
|
220
|
-
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
|
|
221
|
-
* `errors#values` will be removed.
|
|
222
|
-
* `errors#keys` will be removed.
|
|
223
|
-
* `errors#to_xml` will be removed.
|
|
224
|
-
* `errors#to_h` will be removed, and can be replaced with `errors#to_hash`.
|
|
225
|
-
* Manipulating `errors` itself as a hash will have no effect (e.g. `errors[:foo] = 'bar'`).
|
|
226
|
-
* Manipulating the hash returned by `errors#messages` (e.g. `errors.messages[:foo] = 'bar'`) will have no effect.
|
|
227
|
-
* Manipulating the hash returned by `errors#details` (e.g. `errors.details[:foo].clear`) will have no effect.
|
|
138
|
+
* Make ActiveModel::Errors#inspect slimmer for readability
|
|
228
139
|
|
|
229
140
|
*lulalala*
|
|
230
141
|
|
|
231
|
-
|
|
232
|
-
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activemodel/CHANGELOG.md) for previous changes.
|
|
142
|
+
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activemodel/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2004-
|
|
1
|
+
Copyright (c) 2004-2021 David Heinemeier Hansson
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
4
|
a copy of this software and associated documentation files (the
|
|
@@ -18,3 +18,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
data/README.rdoc
CHANGED
|
@@ -16,10 +16,10 @@ Model solves this by defining an explicit API. You can read more about the
|
|
|
16
16
|
API in <tt>ActiveModel::Lint::Tests</tt>.
|
|
17
17
|
|
|
18
18
|
Active Model provides a default module that implements the basic API required
|
|
19
|
-
to integrate with Action Pack out of the box: <tt>ActiveModel::
|
|
19
|
+
to integrate with Action Pack out of the box: <tt>ActiveModel::API</tt>.
|
|
20
20
|
|
|
21
21
|
class Person
|
|
22
|
-
include ActiveModel::
|
|
22
|
+
include ActiveModel::API
|
|
23
23
|
|
|
24
24
|
attr_accessor :name, :age
|
|
25
25
|
validates_presence_of :name
|
|
@@ -32,7 +32,7 @@ to integrate with Action Pack out of the box: <tt>ActiveModel::Model</tt>.
|
|
|
32
32
|
|
|
33
33
|
It includes model name introspections, conversions, translations and
|
|
34
34
|
validations, resulting in a class suitable to be used with Action Pack.
|
|
35
|
-
See <tt>ActiveModel::
|
|
35
|
+
See <tt>ActiveModel::API</tt> for more examples.
|
|
36
36
|
|
|
37
37
|
Active Model also provides the following functionality to have ORM-like
|
|
38
38
|
behavior out of the box:
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveModel
|
|
4
|
+
# == Active \Model \API
|
|
5
|
+
#
|
|
6
|
+
# Includes the required interface for an object to interact with
|
|
7
|
+
# Action Pack and Action View, using different Active Model modules.
|
|
8
|
+
# It includes model name introspections, conversions, translations and
|
|
9
|
+
# validations. Besides that, it allows you to initialize the object with a
|
|
10
|
+
# hash of attributes, pretty much like Active Record does.
|
|
11
|
+
#
|
|
12
|
+
# A minimal implementation could be:
|
|
13
|
+
#
|
|
14
|
+
# class Person
|
|
15
|
+
# include ActiveModel::API
|
|
16
|
+
# attr_accessor :name, :age
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# person = Person.new(name: 'bob', age: '18')
|
|
20
|
+
# person.name # => "bob"
|
|
21
|
+
# person.age # => "18"
|
|
22
|
+
#
|
|
23
|
+
# Note that, by default, <tt>ActiveModel::API</tt> implements <tt>persisted?</tt>
|
|
24
|
+
# to return +false+, which is the most common case. You may want to override
|
|
25
|
+
# it in your class to simulate a different scenario:
|
|
26
|
+
#
|
|
27
|
+
# class Person
|
|
28
|
+
# include ActiveModel::API
|
|
29
|
+
# attr_accessor :id, :name
|
|
30
|
+
#
|
|
31
|
+
# def persisted?
|
|
32
|
+
# self.id.present?
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
36
|
+
# person = Person.new(id: 1, name: 'bob')
|
|
37
|
+
# person.persisted? # => true
|
|
38
|
+
#
|
|
39
|
+
# Also, if for some reason you need to run code on <tt>initialize</tt>, make
|
|
40
|
+
# sure you call +super+ if you want the attributes hash initialization to
|
|
41
|
+
# happen.
|
|
42
|
+
#
|
|
43
|
+
# class Person
|
|
44
|
+
# include ActiveModel::API
|
|
45
|
+
# attr_accessor :id, :name, :omg
|
|
46
|
+
#
|
|
47
|
+
# def initialize(attributes={})
|
|
48
|
+
# super
|
|
49
|
+
# @omg ||= true
|
|
50
|
+
# end
|
|
51
|
+
# end
|
|
52
|
+
#
|
|
53
|
+
# person = Person.new(id: 1, name: 'bob')
|
|
54
|
+
# person.omg # => true
|
|
55
|
+
#
|
|
56
|
+
# For more detailed information on other functionalities available, please
|
|
57
|
+
# refer to the specific modules included in <tt>ActiveModel::API</tt>
|
|
58
|
+
# (see below).
|
|
59
|
+
module API
|
|
60
|
+
extend ActiveSupport::Concern
|
|
61
|
+
include ActiveModel::AttributeAssignment
|
|
62
|
+
include ActiveModel::Validations
|
|
63
|
+
include ActiveModel::Conversion
|
|
64
|
+
|
|
65
|
+
included do
|
|
66
|
+
extend ActiveModel::Naming
|
|
67
|
+
extend ActiveModel::Translation
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Initializes a new model with the given +params+.
|
|
71
|
+
#
|
|
72
|
+
# class Person
|
|
73
|
+
# include ActiveModel::API
|
|
74
|
+
# attr_accessor :name, :age
|
|
75
|
+
# end
|
|
76
|
+
#
|
|
77
|
+
# person = Person.new(name: 'bob', age: '18')
|
|
78
|
+
# person.name # => "bob"
|
|
79
|
+
# person.age # => "18"
|
|
80
|
+
def initialize(attributes = {})
|
|
81
|
+
assign_attributes(attributes) if attributes
|
|
82
|
+
|
|
83
|
+
super()
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Indicates if the model is persisted. Default is +false+.
|
|
87
|
+
#
|
|
88
|
+
# class Person
|
|
89
|
+
# include ActiveModel::API
|
|
90
|
+
# attr_accessor :id, :name
|
|
91
|
+
# end
|
|
92
|
+
#
|
|
93
|
+
# person = Person.new(id: 1, name: 'bob')
|
|
94
|
+
# person.persisted? # => false
|
|
95
|
+
def persisted?
|
|
96
|
+
false
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|