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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -111
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -4
  5. data/lib/active_model/attribute/user_provided_default.rb +1 -2
  6. data/lib/active_model/attribute.rb +21 -21
  7. data/lib/active_model/attribute_assignment.rb +4 -6
  8. data/lib/active_model/attribute_methods.rb +117 -40
  9. data/lib/active_model/attribute_mutation_tracker.rb +90 -33
  10. data/lib/active_model/attribute_set/builder.rb +81 -16
  11. data/lib/active_model/attribute_set/yaml_encoder.rb +1 -2
  12. data/lib/active_model/attribute_set.rb +20 -28
  13. data/lib/active_model/attributes.rb +65 -44
  14. data/lib/active_model/callbacks.rb +11 -9
  15. data/lib/active_model/conversion.rb +1 -1
  16. data/lib/active_model/dirty.rb +51 -101
  17. data/lib/active_model/error.rb +207 -0
  18. data/lib/active_model/errors.rb +347 -155
  19. data/lib/active_model/gem_version.rb +4 -4
  20. data/lib/active_model/lint.rb +1 -1
  21. data/lib/active_model/naming.rb +22 -7
  22. data/lib/active_model/nested_error.rb +22 -0
  23. data/lib/active_model/railtie.rb +6 -0
  24. data/lib/active_model/secure_password.rb +54 -55
  25. data/lib/active_model/serialization.rb +9 -7
  26. data/lib/active_model/serializers/json.rb +17 -9
  27. data/lib/active_model/translation.rb +1 -1
  28. data/lib/active_model/type/big_integer.rb +0 -1
  29. data/lib/active_model/type/binary.rb +1 -1
  30. data/lib/active_model/type/boolean.rb +0 -1
  31. data/lib/active_model/type/date.rb +0 -5
  32. data/lib/active_model/type/date_time.rb +3 -8
  33. data/lib/active_model/type/decimal.rb +0 -1
  34. data/lib/active_model/type/float.rb +2 -3
  35. data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +14 -6
  36. data/lib/active_model/type/helpers/numeric.rb +17 -6
  37. data/lib/active_model/type/helpers/time_value.rb +37 -15
  38. data/lib/active_model/type/helpers/timezone.rb +1 -1
  39. data/lib/active_model/type/immutable_string.rb +14 -11
  40. data/lib/active_model/type/integer.rb +15 -18
  41. data/lib/active_model/type/registry.rb +16 -16
  42. data/lib/active_model/type/string.rb +12 -3
  43. data/lib/active_model/type/time.rb +1 -6
  44. data/lib/active_model/type/value.rb +9 -2
  45. data/lib/active_model/validations/absence.rb +2 -2
  46. data/lib/active_model/validations/acceptance.rb +34 -27
  47. data/lib/active_model/validations/callbacks.rb +15 -16
  48. data/lib/active_model/validations/clusivity.rb +6 -3
  49. data/lib/active_model/validations/confirmation.rb +4 -4
  50. data/lib/active_model/validations/exclusion.rb +1 -1
  51. data/lib/active_model/validations/format.rb +2 -3
  52. data/lib/active_model/validations/inclusion.rb +2 -2
  53. data/lib/active_model/validations/length.rb +3 -3
  54. data/lib/active_model/validations/numericality.rb +58 -44
  55. data/lib/active_model/validations/presence.rb +1 -1
  56. data/lib/active_model/validations/validates.rb +7 -6
  57. data/lib/active_model/validations.rb +6 -9
  58. data/lib/active_model/validator.rb +8 -3
  59. data/lib/active_model.rb +2 -1
  60. metadata +14 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00ff74e146a582069a06258fe8b5d5e3457340d958590ef6f9f7a5d8bbd3c75b
4
- data.tar.gz: 1f00d19269dd49aec1a2db891d62595e7e45d3c4bf2c42cdfc6e583fccbb8894
3
+ metadata.gz: 0e7a4ed58a99f6c30cf533fdf7bee9f9ba73e6a8b6cc67975edc8676e5311c47
4
+ data.tar.gz: 3dae9a4656e3828b7868c5dd1d2b4a7a5f4e0cd7c70a3043fef9efcb0a39454a
5
5
  SHA512:
6
- metadata.gz: 3ceb7660baf4f321a0b67027113594906977d13b9bf4e3c09b353c6274a744f86c6d5acf28190c528445805ba8e89860c691348067e0b1f29b86b5c9c13ac883
7
- data.tar.gz: 9d8ef0e06a870222ea59e12cb15e4950515bd7f2265d814fa6b6bfaa4b976a565e92060b60d424f88cfe172955a0b20ec1d17c1c9671360f400e171096164880
6
+ metadata.gz: 6a574b7e597927a1177b3448c946566bd0546ee888572aa69abbfe95bc41337f7a9ace548cc783c630a69d3b96bd12add61dd71e32c7c39c44b3a17caf0d8bb8
7
+ data.tar.gz: e38f2244209c854b41d4deaf95774d2d9af6c58d039f2118e4c642d61954390e667b3051c185f9d5ba074b0adc40d3f5461bdd5f049aab903a2b24b11e47a46c
data/CHANGELOG.md CHANGED
@@ -1,188 +1,142 @@
1
- ## Rails 5.2.7.1 (April 26, 2022) ##
1
+ ## Rails 6.1.4.6 (February 11, 2022) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 5.2.7 (March 10, 2022) ##
6
+ ## Rails 6.1.4.5 (February 11, 2022) ##
7
7
 
8
8
  * No changes.
9
9
 
10
10
 
11
- ## Rails 5.2.6.3 (March 08, 2022) ##
11
+ ## Rails 6.1.4.4 (December 15, 2021) ##
12
12
 
13
13
  * No changes.
14
14
 
15
15
 
16
- ## Rails 5.2.6.2 (February 11, 2022) ##
16
+ ## Rails 6.1.4.3 (December 14, 2021) ##
17
17
 
18
18
  * No changes.
19
19
 
20
20
 
21
- ## Rails 5.2.6.1 (February 11, 2022) ##
21
+ ## Rails 6.1.4.2 (December 14, 2021) ##
22
22
 
23
23
  * No changes.
24
24
 
25
25
 
26
- ## Rails 5.2.6 (May 05, 2021) ##
26
+ ## Rails 6.1.4.1 (August 19, 2021) ##
27
27
 
28
28
  * No changes.
29
29
 
30
30
 
31
- ## Rails 5.2.5 (March 26, 2021) ##
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
- ## Rails 5.2.4.6 (May 05, 2021) ##
35
+ Exclude +mutations_from_database+ attribute from json as it lead to recursion.
37
36
 
38
- * No changes.
37
+ *Anil Maurya*
39
38
 
40
39
 
41
- ## Rails 5.2.4.5 (February 10, 2021) ##
40
+ ## Rails 6.1.3.2 (May 05, 2021) ##
42
41
 
43
42
  * No changes.
44
43
 
45
44
 
46
- ## Rails 5.2.4.4 (September 09, 2020) ##
45
+ ## Rails 6.1.3.1 (March 26, 2021) ##
47
46
 
48
47
  * No changes.
49
48
 
50
49
 
51
- ## Rails 5.2.4.3 (May 18, 2020) ##
50
+ ## Rails 6.1.3 (February 17, 2021) ##
52
51
 
53
52
  * No changes.
54
53
 
55
54
 
56
- ## Rails 5.2.4.2 (March 19, 2020) ##
55
+ ## Rails 6.1.2.1 (February 10, 2021) ##
57
56
 
58
57
  * No changes.
59
58
 
60
59
 
61
- ## Rails 5.2.4.1 (December 18, 2019) ##
60
+ ## Rails 6.1.2 (February 09, 2021) ##
62
61
 
63
62
  * No changes.
64
63
 
65
64
 
66
- ## Rails 5.2.4 (November 27, 2019) ##
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 5.2.2 (December 04, 2018) ##
70
+ ## Rails 6.1.0 (December 09, 2020) ##
106
71
 
107
- * Fix numericality validator to still use value before type cast except Active Record.
72
+ * Pass in `base` instead of `base_class` to Error.human_attribute_name
108
73
 
109
- Fixes #33651, #33686.
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
- *Ryuta Kamizono*
78
+ *Filipe Sabella*
112
79
 
80
+ * Deprecate marshalling load from legacy attributes format.
113
81
 
114
- ## Rails 5.2.1.1 (November 27, 2018) ##
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
- * Fix to working before/after validation callbacks on multiple contexts.
84
+ * `*_previously_changed?` accepts `:from` and `:to` keyword arguments like `*_changed?`.
137
85
 
138
- *Yoshiyuki Hirano*
86
+ topic.update!(status: :archived)
87
+ topic.status_previously_changed?(from: "active", to: "archived")
88
+ # => true
139
89
 
140
- * Execute `ConfirmationValidator` validation when `_confirmation`'s value is `false`.
90
+ *George Claghorn*
141
91
 
142
- *bogdanvlviv*
92
+ * Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
143
93
 
144
- * Allow passing a Proc or Symbol to length validator options.
94
+ class Animal
95
+ include ActiveModel::Attributes
96
+ attribute :age
97
+ end
145
98
 
146
- *Matt Rohrer*
99
+ animal = Animal.new
100
+ animal.freeze
101
+ animal.age = 25 # => FrozenError, "can't modify a frozen Animal"
147
102
 
148
- * Add method `#merge!` for `ActiveModel::Errors`.
103
+ *Josh Brody*
149
104
 
150
- *Jahfer Husain*
105
+ * Add `*_previously_was` attribute methods when dirty tracking. Example:
151
106
 
152
- * Fix regression in numericality validator when comparing Decimal and Float input
153
- values with more scale than the schema.
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
- *Bradley Priest*
111
+ *DHH*
156
112
 
157
- * Fix methods `#keys`, `#values` in `ActiveModel::Errors`.
113
+ * Encapsulate each validation error as an Error object.
158
114
 
159
- Change `#keys` to only return the keys that don't have empty messages.
115
+ The `ActiveModel`’s `errors` collection is now an array of these Error
116
+ objects, instead of messages/details hash.
160
117
 
161
- Change `#values` to only return the not empty values.
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
- Example:
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
- # Before
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
- # After
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 # => []
183
- person.errors.values # => []
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
- *bogdanvlviv*
139
+ *lulalala*
186
140
 
187
141
 
188
- Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activemodel/CHANGELOG.md) for previous changes.
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2018 David Heinemeier Hansson
1
+ Copyright (c) 2004-2020 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
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, 'starts with z.' if value.to_s[0] == ?z
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/5-2-stable/activemodel
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
- * http://api.rubyonrails.org
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://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
266
+ * https://discuss.rubyonrails.org/c/rubyonrails-core
@@ -44,8 +44,7 @@ module ActiveModel
44
44
  end
45
45
  end
46
46
 
47
- protected
48
-
47
+ private
49
48
  attr_reader :user_provided_value
50
49
  end
51
50
  end
@@ -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, value, type)
9
- FromDatabase.new(name, value, type)
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, value, type, original_attribute = nil)
13
- FromUser.new(name, value, type, original_attribute)
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, value, type)
17
- WithCastValue.new(name, value, type)
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
- protected
136
-
137
- attr_reader :original_attribute
138
- alias_method :assigned?, :original_attribute
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
- def _original_value_for_database
169
- value_before_type_cast
170
- end
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
- if !new_attributes.respond_to?(:stringify_keys)
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
- attributes = new_attributes.stringify_keys
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