activemodel 5.2.8.1 → 6.1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +91 -97
- data/MIT-LICENSE +1 -2
- data/README.rdoc +6 -4
- data/lib/active_model/attribute/user_provided_default.rb +1 -2
- data/lib/active_model/attribute.rb +21 -21
- data/lib/active_model/attribute_assignment.rb +4 -6
- data/lib/active_model/attribute_methods.rb +117 -40
- data/lib/active_model/attribute_mutation_tracker.rb +90 -33
- data/lib/active_model/attribute_set/builder.rb +81 -16
- data/lib/active_model/attribute_set/yaml_encoder.rb +1 -2
- data/lib/active_model/attribute_set.rb +20 -28
- data/lib/active_model/attributes.rb +65 -44
- data/lib/active_model/callbacks.rb +11 -9
- data/lib/active_model/conversion.rb +1 -1
- data/lib/active_model/dirty.rb +51 -101
- data/lib/active_model/error.rb +207 -0
- data/lib/active_model/errors.rb +347 -155
- data/lib/active_model/gem_version.rb +3 -3
- data/lib/active_model/lint.rb +1 -1
- data/lib/active_model/naming.rb +22 -7
- data/lib/active_model/nested_error.rb +22 -0
- data/lib/active_model/railtie.rb +6 -0
- data/lib/active_model/secure_password.rb +55 -55
- data/lib/active_model/serialization.rb +9 -7
- data/lib/active_model/serializers/json.rb +17 -9
- data/lib/active_model/translation.rb +1 -1
- data/lib/active_model/type/big_integer.rb +0 -1
- data/lib/active_model/type/binary.rb +1 -1
- data/lib/active_model/type/boolean.rb +0 -1
- data/lib/active_model/type/date.rb +0 -5
- data/lib/active_model/type/date_time.rb +3 -8
- data/lib/active_model/type/decimal.rb +0 -1
- data/lib/active_model/type/float.rb +2 -3
- data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +14 -6
- data/lib/active_model/type/helpers/numeric.rb +17 -6
- data/lib/active_model/type/helpers/time_value.rb +37 -15
- data/lib/active_model/type/helpers/timezone.rb +1 -1
- data/lib/active_model/type/immutable_string.rb +14 -11
- data/lib/active_model/type/integer.rb +15 -18
- data/lib/active_model/type/registry.rb +17 -19
- data/lib/active_model/type/string.rb +12 -3
- data/lib/active_model/type/time.rb +1 -6
- data/lib/active_model/type/value.rb +9 -2
- data/lib/active_model/type.rb +3 -2
- data/lib/active_model/validations/absence.rb +2 -2
- data/lib/active_model/validations/acceptance.rb +34 -27
- data/lib/active_model/validations/callbacks.rb +15 -16
- data/lib/active_model/validations/clusivity.rb +6 -3
- data/lib/active_model/validations/confirmation.rb +4 -4
- data/lib/active_model/validations/exclusion.rb +1 -1
- data/lib/active_model/validations/format.rb +2 -3
- data/lib/active_model/validations/inclusion.rb +2 -2
- data/lib/active_model/validations/length.rb +3 -3
- data/lib/active_model/validations/numericality.rb +58 -44
- data/lib/active_model/validations/presence.rb +1 -1
- data/lib/active_model/validations/validates.rb +7 -6
- data/lib/active_model/validations.rb +6 -9
- data/lib/active_model/validator.rb +8 -3
- data/lib/active_model.rb +2 -1
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae24a33b1bbfa6eb1e4c5e55f14a7bb92631f3c16b894fe516e01507f3a3354f
|
4
|
+
data.tar.gz: fa7badebe0d2d6213db0e1122bb94fbff72cbc11fe1e8bce870ed1b340a8f31b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd715570f3cba8ebe323210ac537b2ca5852cf1827cd791cd8b023f01d848047d0b0e52d205a99a49f310ea81fb9accbc404de5d7d53f2c629a83cd7a5ae7d7f
|
7
|
+
data.tar.gz: 80284508ce715c8335715acff27814c89e40036d2c107f3684cf97741a50e7cc188b25636ee5c3f01ea4ec0c74c34367aa4eb3daa1ebc7a93ad2946c568670a9
|
data/CHANGELOG.md
CHANGED
@@ -1,198 +1,192 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.1.6.1 (July 12, 2022) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails 5.
|
6
|
+
## Rails 6.1.5.1 (April 26, 2022) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails
|
11
|
+
## Rails 6.1.5 (March 09, 2022) ##
|
12
12
|
|
13
|
-
*
|
13
|
+
* Clear secure password cache if password is set to `nil`
|
14
14
|
|
15
|
+
Before:
|
15
16
|
|
16
|
-
|
17
|
+
user.password = 'something'
|
18
|
+
user.password = nil
|
17
19
|
|
18
|
-
|
20
|
+
user.password # => 'something'
|
19
21
|
|
22
|
+
Now:
|
20
23
|
|
21
|
-
|
24
|
+
user.password = 'something'
|
25
|
+
user.password = nil
|
22
26
|
|
23
|
-
|
27
|
+
user.password # => nil
|
24
28
|
|
29
|
+
*Markus Doits*
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
* No changes.
|
31
|
+
* Fix delegation in `ActiveModel::Type::Registry#lookup` and `ActiveModel::Type.lookup`
|
29
32
|
|
33
|
+
Passing a last positional argument `{}` would be incorrectly considered as keyword argument.
|
30
34
|
|
31
|
-
|
35
|
+
*Benoit Daloze*
|
32
36
|
|
33
|
-
*
|
37
|
+
* Fix `to_json` after `changes_applied` for `ActiveModel::Dirty` object.
|
34
38
|
|
35
|
-
|
36
|
-
## Rails 5.2.6 (May 05, 2021) ##
|
37
|
-
|
38
|
-
* No changes.
|
39
|
+
*Ryuta Kamizono*
|
39
40
|
|
40
41
|
|
41
|
-
## Rails
|
42
|
+
## Rails 6.1.4.7 (March 08, 2022) ##
|
42
43
|
|
43
44
|
* No changes.
|
44
45
|
|
45
46
|
|
46
|
-
## Rails
|
47
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
47
48
|
|
48
49
|
* No changes.
|
49
50
|
|
50
51
|
|
51
|
-
## Rails
|
52
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
52
53
|
|
53
54
|
* No changes.
|
54
55
|
|
55
56
|
|
56
|
-
## Rails
|
57
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
57
58
|
|
58
59
|
* No changes.
|
59
60
|
|
60
61
|
|
61
|
-
## Rails
|
62
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
62
63
|
|
63
64
|
* No changes.
|
64
65
|
|
65
66
|
|
66
|
-
## Rails
|
67
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
67
68
|
|
68
69
|
* No changes.
|
69
70
|
|
70
71
|
|
71
|
-
## Rails
|
72
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
72
73
|
|
73
74
|
* No changes.
|
74
75
|
|
75
76
|
|
76
|
-
## Rails
|
77
|
-
|
78
|
-
* Type cast falsy boolean symbols on boolean attribute as false.
|
79
|
-
|
80
|
-
Fixes #35676.
|
81
|
-
|
82
|
-
*Ryuta Kamizono*
|
77
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
83
78
|
|
79
|
+
* Fix `to_json` for `ActiveModel::Dirty` object.
|
84
80
|
|
85
|
-
|
81
|
+
Exclude +mutations_from_database+ attribute from json as it lead to recursion.
|
86
82
|
|
87
|
-
*
|
88
|
-
from Gregorian date to Julian date.
|
89
|
-
|
90
|
-
Before:
|
83
|
+
*Anil Maurya*
|
91
84
|
|
92
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
93
|
-
=> #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
|
94
85
|
|
95
|
-
|
86
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
96
87
|
|
97
|
-
|
98
|
-
=> #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
|
99
|
-
|
100
|
-
Fixes #28521.
|
88
|
+
* No changes.
|
101
89
|
|
102
|
-
*Sayan Chakraborty*
|
103
90
|
|
104
|
-
|
105
|
-
by casting to `BigDecimal` on both ends of the validation.
|
91
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
106
92
|
|
107
|
-
|
93
|
+
* No changes.
|
108
94
|
|
109
95
|
|
110
|
-
## Rails
|
96
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
111
97
|
|
112
98
|
* No changes.
|
113
99
|
|
114
100
|
|
115
|
-
## Rails
|
101
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
116
102
|
|
117
|
-
*
|
118
|
-
|
119
|
-
Fixes #33651, #33686.
|
120
|
-
|
121
|
-
*Ryuta Kamizono*
|
103
|
+
* No changes.
|
122
104
|
|
123
105
|
|
124
|
-
## Rails
|
106
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
125
107
|
|
126
108
|
* No changes.
|
127
109
|
|
128
110
|
|
129
|
-
## Rails
|
111
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
130
112
|
|
131
113
|
* No changes.
|
132
114
|
|
133
115
|
|
134
|
-
## Rails
|
116
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
117
|
+
|
118
|
+
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
135
119
|
|
136
|
-
|
120
|
+
This is useful in cases where the `human_attribute_name` method depends
|
121
|
+
on other attributes' values of the class under validation to derive what the
|
122
|
+
attribute name should be.
|
137
123
|
|
138
|
-
*
|
124
|
+
*Filipe Sabella*
|
139
125
|
|
140
|
-
*
|
126
|
+
* Deprecate marshalling load from legacy attributes format.
|
141
127
|
|
142
|
-
|
128
|
+
*Ryuta Kamizono*
|
143
129
|
|
144
|
-
|
130
|
+
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
|
145
131
|
|
146
|
-
|
132
|
+
topic.update!(status: :archived)
|
133
|
+
topic.status_previously_changed?(from: "active", to: "archived")
|
134
|
+
# => true
|
147
135
|
|
148
|
-
*
|
136
|
+
*George Claghorn*
|
149
137
|
|
150
|
-
*
|
138
|
+
* Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
|
151
139
|
|
152
|
-
|
140
|
+
class Animal
|
141
|
+
include ActiveModel::Attributes
|
142
|
+
attribute :age
|
143
|
+
end
|
153
144
|
|
154
|
-
|
145
|
+
animal = Animal.new
|
146
|
+
animal.freeze
|
147
|
+
animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
|
155
148
|
|
156
|
-
*
|
149
|
+
*Josh Brody*
|
157
150
|
|
158
|
-
* Add
|
151
|
+
* Add `*_previously_was` attribute methods when dirty tracking. Example:
|
159
152
|
|
160
|
-
|
153
|
+
pirate.update(catchphrase: "Ahoy!")
|
154
|
+
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
|
155
|
+
pirate.catchphrase_previously_was # => "Thar She Blows!"
|
161
156
|
|
162
|
-
*
|
163
|
-
values with more scale than the schema.
|
157
|
+
*DHH*
|
164
158
|
|
165
|
-
|
159
|
+
* Encapsulate each validation error as an Error object.
|
166
160
|
|
167
|
-
|
161
|
+
The `ActiveModel`’s `errors` collection is now an array of these Error
|
162
|
+
objects, instead of messages/details hash.
|
168
163
|
|
169
|
-
|
164
|
+
For each of these `Error` object, its `message` and `full_message` methods
|
165
|
+
are for generating error messages. Its `details` method would return error’s
|
166
|
+
extra parameters, found in the original `details` hash.
|
170
167
|
|
171
|
-
|
168
|
+
The change tries its best at maintaining backward compatibility, however
|
169
|
+
some edge cases won’t be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
|
170
|
+
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
|
171
|
+
please convert those direct manipulations to use provided API methods instead.
|
172
|
+
Please note that `errors#add` now accepts `options` as keyword arguments instead of `Hash` which
|
173
|
+
introduced a change in Ruby 3 to [keyword arguments][kwargs-ann].
|
172
174
|
|
173
|
-
|
175
|
+
[kwargs-ann]: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
|
174
176
|
|
175
|
-
|
176
|
-
person = Person.new
|
177
|
-
person.errors.keys # => []
|
178
|
-
person.errors.values # => []
|
179
|
-
person.errors.messages # => {}
|
180
|
-
person.errors[:name] # => []
|
181
|
-
person.errors.messages # => {:name => []}
|
182
|
-
person.errors.keys # => [:name]
|
183
|
-
person.errors.values # => [[]]
|
177
|
+
The list of deprecated methods and their planned future behavioral changes at the next major release are:
|
184
178
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
179
|
+
* `errors#slice!` will be removed.
|
180
|
+
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
|
181
|
+
* `errors#values` will be removed.
|
182
|
+
* `errors#keys` will be removed.
|
183
|
+
* `errors#to_xml` will be removed.
|
184
|
+
* `errors#to_h` will be removed, and can be replaced with `errors#to_hash`.
|
185
|
+
* Manipulating `errors` itself as a hash will have no effect (e.g. `errors[:foo] = 'bar'`).
|
186
|
+
* Manipulating the hash returned by `errors#messages` (e.g. `errors.messages[:foo] = 'bar'`) will have no effect.
|
187
|
+
* Manipulating the hash returned by `errors#details` (e.g. `errors.details[:foo].clear`) will have no effect.
|
194
188
|
|
195
|
-
*
|
189
|
+
*lulalala*
|
196
190
|
|
197
191
|
|
198
|
-
Please check [
|
192
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activemodel/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2004-
|
1
|
+
Copyright (c) 2004-2022 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,4 +18,3 @@ 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
@@ -5,6 +5,8 @@ They allow for Action Pack helpers to interact with non-Active Record models,
|
|
5
5
|
for example. Active Model also helps with building custom ORMs for use outside of
|
6
6
|
the Rails framework.
|
7
7
|
|
8
|
+
You can read more about Active Model in the {Active Model Basics}[https://edgeguides.rubyonrails.org/active_model_basics.html] guide.
|
9
|
+
|
8
10
|
Prior to Rails 3.0, if a plugin or gem developer wanted to have an object
|
9
11
|
interact with Action Pack helpers, it was required to either copy chunks of
|
10
12
|
code from Rails, or monkey patch entire helpers to make them handle objects
|
@@ -198,7 +200,7 @@ behavior out of the box:
|
|
198
200
|
attr_accessor :first_name, :last_name
|
199
201
|
|
200
202
|
validates_each :first_name, :last_name do |record, attr, value|
|
201
|
-
record.errors.add attr,
|
203
|
+
record.errors.add attr, "starts with z." if value.start_with?("z")
|
202
204
|
end
|
203
205
|
end
|
204
206
|
|
@@ -239,7 +241,7 @@ The latest version of Active Model can be installed with RubyGems:
|
|
239
241
|
|
240
242
|
Source code can be downloaded as part of the Rails project on GitHub
|
241
243
|
|
242
|
-
* https://github.com/rails/rails/tree/
|
244
|
+
* https://github.com/rails/rails/tree/main/activemodel
|
243
245
|
|
244
246
|
|
245
247
|
== License
|
@@ -253,7 +255,7 @@ Active Model is released under the MIT license:
|
|
253
255
|
|
254
256
|
API documentation is at:
|
255
257
|
|
256
|
-
*
|
258
|
+
* https://api.rubyonrails.org
|
257
259
|
|
258
260
|
Bug reports for the Ruby on Rails project can be filed here:
|
259
261
|
|
@@ -261,4 +263,4 @@ Bug reports for the Ruby on Rails project can be filed here:
|
|
261
263
|
|
262
264
|
Feature requests should be discussed on the rails-core mailing list here:
|
263
265
|
|
264
|
-
* https://
|
266
|
+
* https://discuss.rubyonrails.org/c/rubyonrails-core
|
@@ -5,16 +5,16 @@ require "active_support/core_ext/object/duplicable"
|
|
5
5
|
module ActiveModel
|
6
6
|
class Attribute # :nodoc:
|
7
7
|
class << self
|
8
|
-
def from_database(name,
|
9
|
-
FromDatabase.new(name,
|
8
|
+
def from_database(name, value_before_type_cast, type, value = nil)
|
9
|
+
FromDatabase.new(name, value_before_type_cast, type, nil, value)
|
10
10
|
end
|
11
11
|
|
12
|
-
def from_user(name,
|
13
|
-
FromUser.new(name,
|
12
|
+
def from_user(name, value_before_type_cast, type, original_attribute = nil)
|
13
|
+
FromUser.new(name, value_before_type_cast, type, original_attribute)
|
14
14
|
end
|
15
15
|
|
16
|
-
def with_cast_value(name,
|
17
|
-
WithCastValue.new(name,
|
16
|
+
def with_cast_value(name, value_before_type_cast, type)
|
17
|
+
WithCastValue.new(name, value_before_type_cast, type)
|
18
18
|
end
|
19
19
|
|
20
20
|
def null(name)
|
@@ -30,11 +30,12 @@ module ActiveModel
|
|
30
30
|
|
31
31
|
# This method should not be called directly.
|
32
32
|
# Use #from_database or #from_user
|
33
|
-
def initialize(name, value_before_type_cast, type, original_attribute = nil)
|
33
|
+
def initialize(name, value_before_type_cast, type, original_attribute = nil, value = nil)
|
34
34
|
@name = name
|
35
35
|
@value_before_type_cast = value_before_type_cast
|
36
36
|
@type = type
|
37
37
|
@original_attribute = original_attribute
|
38
|
+
@value = value unless value.nil?
|
38
39
|
end
|
39
40
|
|
40
41
|
def value
|
@@ -132,20 +133,18 @@ module ActiveModel
|
|
132
133
|
coder["value"] = value if defined?(@value)
|
133
134
|
end
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
def original_value_for_database
|
141
|
-
if assigned?
|
142
|
-
original_attribute.original_value_for_database
|
143
|
-
else
|
144
|
-
_original_value_for_database
|
145
|
-
end
|
136
|
+
def original_value_for_database
|
137
|
+
if assigned?
|
138
|
+
original_attribute.original_value_for_database
|
139
|
+
else
|
140
|
+
_original_value_for_database
|
146
141
|
end
|
142
|
+
end
|
147
143
|
|
148
144
|
private
|
145
|
+
attr_reader :original_attribute
|
146
|
+
alias :assigned? :original_attribute
|
147
|
+
|
149
148
|
def initialize_dup(other)
|
150
149
|
if defined?(@value) && @value.duplicable?
|
151
150
|
@value = @value.dup
|
@@ -165,9 +164,10 @@ module ActiveModel
|
|
165
164
|
type.deserialize(value)
|
166
165
|
end
|
167
166
|
|
168
|
-
|
169
|
-
|
170
|
-
|
167
|
+
private
|
168
|
+
def _original_value_for_database
|
169
|
+
value_before_type_cast
|
170
|
+
end
|
171
171
|
end
|
172
172
|
|
173
173
|
class FromUser < Attribute # :nodoc:
|
@@ -26,19 +26,17 @@ module ActiveModel
|
|
26
26
|
# cat.name # => 'Gorby'
|
27
27
|
# cat.status # => 'sleeping'
|
28
28
|
def assign_attributes(new_attributes)
|
29
|
-
|
30
|
-
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
|
29
|
+
unless new_attributes.respond_to?(:each_pair)
|
30
|
+
raise ArgumentError, "When assigning attributes, you must pass a hash as an argument, #{new_attributes.class} passed."
|
31
31
|
end
|
32
32
|
return if new_attributes.empty?
|
33
33
|
|
34
|
-
|
35
|
-
_assign_attributes(sanitize_for_mass_assignment(attributes))
|
34
|
+
_assign_attributes(sanitize_for_mass_assignment(new_attributes))
|
36
35
|
end
|
37
36
|
|
38
37
|
alias attributes= assign_attributes
|
39
38
|
|
40
39
|
private
|
41
|
-
|
42
40
|
def _assign_attributes(attributes)
|
43
41
|
attributes.each do |k, v|
|
44
42
|
_assign_attribute(k, v)
|
@@ -50,7 +48,7 @@ module ActiveModel
|
|
50
48
|
if respond_to?(setter)
|
51
49
|
public_send(setter, v)
|
52
50
|
else
|
53
|
-
raise UnknownAttributeError.new(self, k)
|
51
|
+
raise UnknownAttributeError.new(self, k.to_s)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|