activemodel 5.2.7.1 → 6.1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -111
- data/MIT-LICENSE +1 -1
- 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 +4 -4
- 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 +54 -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 +16 -16
- 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/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 +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e7a4ed58a99f6c30cf533fdf7bee9f9ba73e6a8b6cc67975edc8676e5311c47
|
4
|
+
data.tar.gz: 3dae9a4656e3828b7868c5dd1d2b4a7a5f4e0cd7c70a3043fef9efcb0a39454a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a574b7e597927a1177b3448c946566bd0546ee888572aa69abbfe95bc41337f7a9ace548cc783c630a69d3b96bd12add61dd71e32c7c39c44b3a17caf0d8bb8
|
7
|
+
data.tar.gz: e38f2244209c854b41d4deaf95774d2d9af6c58d039f2118e4c642d61954390e667b3051c185f9d5ba074b0adc40d3f5461bdd5f049aab903a2b24b11e47a46c
|
data/CHANGELOG.md
CHANGED
@@ -1,188 +1,142 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails
|
6
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails
|
11
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
12
12
|
|
13
13
|
* No changes.
|
14
14
|
|
15
15
|
|
16
|
-
## Rails
|
16
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
17
17
|
|
18
18
|
* No changes.
|
19
19
|
|
20
20
|
|
21
|
-
## Rails
|
21
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
22
22
|
|
23
23
|
* No changes.
|
24
24
|
|
25
25
|
|
26
|
-
## Rails
|
26
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
27
27
|
|
28
28
|
* No changes.
|
29
29
|
|
30
30
|
|
31
|
-
## Rails
|
32
|
-
|
33
|
-
* No changes.
|
31
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
34
32
|
|
33
|
+
* Fix `to_json` for `ActiveModel::Dirty` object.
|
35
34
|
|
36
|
-
|
35
|
+
Exclude +mutations_from_database+ attribute from json as it lead to recursion.
|
37
36
|
|
38
|
-
*
|
37
|
+
*Anil Maurya*
|
39
38
|
|
40
39
|
|
41
|
-
## Rails
|
40
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
42
41
|
|
43
42
|
* No changes.
|
44
43
|
|
45
44
|
|
46
|
-
## Rails
|
45
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
47
46
|
|
48
47
|
* No changes.
|
49
48
|
|
50
49
|
|
51
|
-
## Rails
|
50
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
52
51
|
|
53
52
|
* No changes.
|
54
53
|
|
55
54
|
|
56
|
-
## Rails
|
55
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
57
56
|
|
58
57
|
* No changes.
|
59
58
|
|
60
59
|
|
61
|
-
## Rails
|
60
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
62
61
|
|
63
62
|
* No changes.
|
64
63
|
|
65
64
|
|
66
|
-
## Rails
|
67
|
-
|
68
|
-
* Type cast falsy boolean symbols on boolean attribute as false.
|
69
|
-
|
70
|
-
Fixes #35676.
|
71
|
-
|
72
|
-
*Ryuta Kamizono*
|
73
|
-
|
74
|
-
|
75
|
-
## Rails 5.2.3 (March 27, 2019) ##
|
76
|
-
|
77
|
-
* Fix date value when casting a multiparameter date hash to not convert
|
78
|
-
from Gregorian date to Julian date.
|
79
|
-
|
80
|
-
Before:
|
81
|
-
|
82
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
83
|
-
=> #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
|
84
|
-
|
85
|
-
After:
|
86
|
-
|
87
|
-
Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
|
88
|
-
=> #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
|
89
|
-
|
90
|
-
Fixes #28521.
|
91
|
-
|
92
|
-
*Sayan Chakraborty*
|
93
|
-
|
94
|
-
* Fix numericality equality validation of `BigDecimal` and `Float`
|
95
|
-
by casting to `BigDecimal` on both ends of the validation.
|
96
|
-
|
97
|
-
*Gannon McGibbon*
|
98
|
-
|
99
|
-
|
100
|
-
## Rails 5.2.2.1 (March 11, 2019) ##
|
65
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
101
66
|
|
102
67
|
* No changes.
|
103
68
|
|
104
69
|
|
105
|
-
## Rails
|
70
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
106
71
|
|
107
|
-
*
|
72
|
+
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
108
73
|
|
109
|
-
|
74
|
+
This is useful in cases where the `human_attribute_name` method depends
|
75
|
+
on other attributes' values of the class under validation to derive what the
|
76
|
+
attribute name should be.
|
110
77
|
|
111
|
-
*
|
78
|
+
*Filipe Sabella*
|
112
79
|
|
80
|
+
* Deprecate marshalling load from legacy attributes format.
|
113
81
|
|
114
|
-
|
115
|
-
|
116
|
-
* No changes.
|
117
|
-
|
118
|
-
|
119
|
-
## Rails 5.2.1 (August 07, 2018) ##
|
120
|
-
|
121
|
-
* No changes.
|
122
|
-
|
123
|
-
|
124
|
-
## Rails 5.2.0 (April 09, 2018) ##
|
125
|
-
|
126
|
-
* Do not lose all multiple `:includes` with options in serialization.
|
127
|
-
|
128
|
-
*Mike Mangino*
|
129
|
-
|
130
|
-
* Models using the attributes API with a proc default can now be marshalled.
|
131
|
-
|
132
|
-
Fixes #31216.
|
133
|
-
|
134
|
-
*Sean Griffin*
|
82
|
+
*Ryuta Kamizono*
|
135
83
|
|
136
|
-
*
|
84
|
+
* `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
|
137
85
|
|
138
|
-
|
86
|
+
topic.update!(status: :archived)
|
87
|
+
topic.status_previously_changed?(from: "active", to: "archived")
|
88
|
+
# => true
|
139
89
|
|
140
|
-
*
|
90
|
+
*George Claghorn*
|
141
91
|
|
142
|
-
|
92
|
+
* Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
|
143
93
|
|
144
|
-
|
94
|
+
class Animal
|
95
|
+
include ActiveModel::Attributes
|
96
|
+
attribute :age
|
97
|
+
end
|
145
98
|
|
146
|
-
|
99
|
+
animal = Animal.new
|
100
|
+
animal.freeze
|
101
|
+
animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
|
147
102
|
|
148
|
-
*
|
103
|
+
*Josh Brody*
|
149
104
|
|
150
|
-
|
105
|
+
* Add `*_previously_was` attribute methods when dirty tracking. Example:
|
151
106
|
|
152
|
-
|
153
|
-
|
107
|
+
pirate.update(catchphrase: "Ahoy!")
|
108
|
+
pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"]
|
109
|
+
pirate.catchphrase_previously_was # => "Thar She Blows!"
|
154
110
|
|
155
|
-
*
|
111
|
+
*DHH*
|
156
112
|
|
157
|
-
*
|
113
|
+
* Encapsulate each validation error as an Error object.
|
158
114
|
|
159
|
-
|
115
|
+
The `ActiveModel`’s `errors` collection is now an array of these Error
|
116
|
+
objects, instead of messages/details hash.
|
160
117
|
|
161
|
-
|
118
|
+
For each of these `Error` object, its `message` and `full_message` methods
|
119
|
+
are for generating error messages. Its `details` method would return error’s
|
120
|
+
extra parameters, found in the original `details` hash.
|
162
121
|
|
163
|
-
|
122
|
+
The change tries its best at maintaining backward compatibility, however
|
123
|
+
some edge cases won’t be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
|
124
|
+
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
|
125
|
+
please convert those direct manipulations to use provided API methods instead.
|
164
126
|
|
165
|
-
|
166
|
-
person = Person.new
|
167
|
-
person.errors.keys # => []
|
168
|
-
person.errors.values # => []
|
169
|
-
person.errors.messages # => {}
|
170
|
-
person.errors[:name] # => []
|
171
|
-
person.errors.messages # => {:name => []}
|
172
|
-
person.errors.keys # => [:name]
|
173
|
-
person.errors.values # => [[]]
|
127
|
+
The list of deprecated methods and their planned future behavioral changes at the next major release are:
|
174
128
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
129
|
+
* `errors#slice!` will be removed.
|
130
|
+
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
|
131
|
+
* `errors#values` will be removed.
|
132
|
+
* `errors#keys` will be removed.
|
133
|
+
* `errors#to_xml` will be removed.
|
134
|
+
* `errors#to_h` will be removed, and can be replaced with `errors#to_hash`.
|
135
|
+
* Manipulating `errors` itself as a hash will have no effect (e.g. `errors[:foo] = 'bar'`).
|
136
|
+
* Manipulating the hash returned by `errors#messages` (e.g. `errors.messages[:foo] = 'bar'`) will have no effect.
|
137
|
+
* Manipulating the hash returned by `errors#details` (e.g. `errors.details[:foo].clear`) will have no effect.
|
184
138
|
|
185
|
-
*
|
139
|
+
*lulalala*
|
186
140
|
|
187
141
|
|
188
|
-
Please check [
|
142
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activemodel/CHANGELOG.md) for previous changes.
|
data/MIT-LICENSE
CHANGED
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
|