activemodel 5.0.7.2 → 5.1.0.beta1

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 +5 -5
  2. data/CHANGELOG.md +15 -219
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +1 -1
  5. data/lib/active_model.rb +11 -12
  6. data/lib/active_model/attribute_assignment.rb +11 -11
  7. data/lib/active_model/attribute_methods.rb +13 -15
  8. data/lib/active_model/callbacks.rb +19 -20
  9. data/lib/active_model/conversion.rb +12 -3
  10. data/lib/active_model/dirty.rb +14 -14
  11. data/lib/active_model/errors.rb +27 -103
  12. data/lib/active_model/forbidden_attributes_protection.rb +1 -1
  13. data/lib/active_model/gem_version.rb +3 -3
  14. data/lib/active_model/lint.rb +0 -1
  15. data/lib/active_model/model.rb +3 -4
  16. data/lib/active_model/naming.rb +9 -10
  17. data/lib/active_model/secure_password.rb +1 -1
  18. data/lib/active_model/serialization.rb +2 -2
  19. data/lib/active_model/serializers/json.rb +2 -2
  20. data/lib/active_model/translation.rb +2 -3
  21. data/lib/active_model/type.rb +15 -19
  22. data/lib/active_model/type/big_integer.rb +4 -4
  23. data/lib/active_model/type/binary.rb +1 -1
  24. data/lib/active_model/type/boolean.rb +20 -9
  25. data/lib/active_model/type/date.rb +25 -25
  26. data/lib/active_model/type/date_time.rb +21 -21
  27. data/lib/active_model/type/decimal.rb +35 -39
  28. data/lib/active_model/type/float.rb +17 -8
  29. data/lib/active_model/type/helpers.rb +4 -4
  30. data/lib/active_model/type/helpers/accepts_multiparameter_time.rb +2 -2
  31. data/lib/active_model/type/helpers/mutable.rb +2 -2
  32. data/lib/active_model/type/helpers/numeric.rb +18 -17
  33. data/lib/active_model/type/helpers/time_value.rb +23 -23
  34. data/lib/active_model/type/immutable_string.rb +9 -8
  35. data/lib/active_model/type/integer.rb +23 -21
  36. data/lib/active_model/type/registry.rb +12 -8
  37. data/lib/active_model/type/string.rb +1 -6
  38. data/lib/active_model/type/time.rb +15 -11
  39. data/lib/active_model/type/value.rb +6 -6
  40. data/lib/active_model/validations.rb +9 -12
  41. data/lib/active_model/validations/absence.rb +1 -1
  42. data/lib/active_model/validations/acceptance.rb +41 -40
  43. data/lib/active_model/validations/callbacks.rb +4 -7
  44. data/lib/active_model/validations/clusivity.rb +7 -7
  45. data/lib/active_model/validations/confirmation.rb +15 -16
  46. data/lib/active_model/validations/exclusion.rb +1 -2
  47. data/lib/active_model/validations/format.rb +24 -24
  48. data/lib/active_model/validations/inclusion.rb +1 -2
  49. data/lib/active_model/validations/length.rb +6 -42
  50. data/lib/active_model/validations/numericality.rb +3 -11
  51. data/lib/active_model/validations/presence.rb +1 -2
  52. data/lib/active_model/validations/validates.rb +6 -6
  53. data/lib/active_model/validations/with.rb +4 -2
  54. data/lib/active_model/validator.rb +5 -6
  55. data/lib/active_model/version.rb +1 -1
  56. metadata +8 -11
  57. data/lib/active_model/test_case.rb +0 -4
  58. data/lib/active_model/type/decimal_without_scale.rb +0 -11
  59. data/lib/active_model/type/text.rb +0 -11
  60. data/lib/active_model/type/unsigned_integer.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 037004e060b00ef9bdf166f1a123941008eac38445bf7b69de9e4325d27ad729
4
- data.tar.gz: 323b17aae456ed4bd2e606dc308edee6cb3abc945d806fb753248e5bc4fe2f7d
2
+ SHA1:
3
+ metadata.gz: 2722a2216da7e44da498eddfe9cd283628ff4876
4
+ data.tar.gz: f7d850f4021cf5f4fd5e4209f9359d645bf1d69f
5
5
  SHA512:
6
- metadata.gz: ad0dec431b9629aa031fbe36c6ae295f51a2d773fa9e325833189d177201c81c678aee6eb1298607a894a415dd0d1bd0f83e91f6edc7785b7b390af6c9e43b89
7
- data.tar.gz: 7f5c74e105297822c1d10e088a6aa16641f5cefa6d3d71fde2a2d0e0495bf10565403cb8cd66c00cd241477bb80c997ba1d5a5be3b98ef3dbd8f3d4e142d6186
6
+ metadata.gz: 6ce16354bc976631475e670f614393ab7859e2cbd32e1348f6d5c58b714ae336af91312b4fcbc3b90346e616c96ab1e03caf8ada1d48a1760aaa49350751c8eb
7
+ data.tar.gz: b1a4b60136a4a1df7147359ba25f4fb15d366234e65cfb6f965cc8007d7d72289c02a3a9798249ae9216378d74022af18db6ad948469b95e9dacd8952638b3f1
@@ -1,236 +1,32 @@
1
- ## Rails 5.0.7.2 (March 11, 2019) ##
1
+ ## Rails 5.1.0.beta1 (February 23, 2017) ##
2
2
 
3
- * No changes.
3
+ * Remove deprecated behavior that halts callbacks when the return is false.
4
4
 
5
+ *Rafael Mendonça França*
5
6
 
6
- ## Rails 5.0.7.1 (November 27, 2018) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 5.0.7 (March 29, 2018) ##
12
-
13
- * No changes.
14
-
15
-
16
- ## Rails 5.0.6 (September 07, 2017) ##
17
-
18
- * No changes.
19
-
20
-
21
- ## Rails 5.0.6.rc1 (August 24, 2017) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 5.0.5 (July 31, 2017) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 5.0.5.rc2 (July 25, 2017) ##
32
-
33
- * No changes.
34
-
35
-
36
- ## Rails 5.0.5.rc1 (July 19, 2017) ##
37
-
38
- * No changes.
39
-
40
-
41
- ## Rails 5.0.4 (June 19, 2017) ##
42
-
43
- * Fix regression in numericality validator when comparing Decimal and Float input
44
- values with more scale than the schema.
45
-
46
- *Bradley Priest*
47
-
48
-
49
- ## Rails 5.0.3 (May 12, 2017) ##
50
-
51
- * The original string assigned to a model attribute is no longer incorrectly
52
- frozen.
53
-
54
- Fixes #24185, #28718.
55
-
56
- *Matthew Draper*
57
-
58
- * Avoid converting integer as a string into float.
59
-
60
- *namusyaka*
61
-
62
-
63
- ## Rails 5.0.2 (March 01, 2017) ##
64
-
65
- * No changes.
66
-
67
-
68
- ## Rails 5.0.1 (December 21, 2016) ##
69
-
70
- * No changes.
71
-
72
-
73
- ## Rails 5.0.1.rc2 (December 10, 2016) ##
74
-
75
- * No changes.
76
-
77
-
78
- ## Rails 5.0.1.rc1 (December 01, 2016) ##
79
-
80
- * Fix `Type::Date#serialize` to cast a value to a date object properly.
81
- This casting fixes queries for finding records by date column.
82
-
83
- Fixes #25354.
84
-
85
- *Ryuta Kamizono*
86
-
87
-
88
- ## Rails 5.0.0 (June 30, 2016) ##
89
-
90
- * `Dirty`'s `*_changed?` methods now return an actual singleton, never `nil`, as in 4.2.
91
- Fixes #24220.
92
-
93
- *Sen-Zhang*
94
-
95
- * Ensure that instances of `ActiveModel::Errors` can be marshalled.
96
- Fixes #25165.
97
-
98
- *Sean Griffin*
99
-
100
- * Allow passing record being validated to the message proc to generate
101
- customized error messages for that object using I18n helper.
102
-
103
- *Prathamesh Sonpatki*
104
-
105
- * Validate multiple contexts on `valid?` and `invalid?` at once.
106
-
107
- Example:
108
-
109
- class Person
110
- include ActiveModel::Validations
111
-
112
- attr_reader :name, :title
113
- validates_presence_of :name, on: :create
114
- validates_presence_of :title, on: :update
115
- end
116
-
117
- person = Person.new
118
- person.valid?([:create, :update]) # => false
119
- person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]}
120
-
121
- *Dmitry Polushkin*
122
-
123
- * Add case_sensitive option for confirmation validator in models.
124
-
125
- *Akshat Sharma*
126
-
127
- * Ensure `method_missing` is called for methods passed to
128
- `ActiveModel::Serialization#serializable_hash` that don't exist.
129
-
130
- *Jay Elaraj*
131
-
132
- * Remove `ActiveModel::Serializers::Xml` from core.
133
-
134
- *Zachary Scott*
135
-
136
- * Add `ActiveModel::Dirty#[attr_name]_previously_changed?` and
137
- `ActiveModel::Dirty#[attr_name]_previous_change` to improve access
138
- to recorded changes after the model has been saved.
139
-
140
- It makes the dirty-attributes query methods consistent before and after
141
- saving.
142
-
143
- *Fernando Tapia Rico*
144
-
145
- * Deprecate the `:tokenizer` option for `validates_length_of`, in favor of
146
- plain Ruby.
147
-
148
- *Sean Griffin*
149
-
150
- * Deprecate `ActiveModel::Errors#add_on_empty` and `ActiveModel::Errors#add_on_blank`
151
- with no replacement.
152
-
153
- *Wojciech Wnętrzak*
154
-
155
- * Deprecate `ActiveModel::Errors#get`, `ActiveModel::Errors#set` and
156
- `ActiveModel::Errors#[]=` methods that have inconsistent behavior.
157
-
158
- *Wojciech Wnętrzak*
159
-
160
- * Allow symbol as values for `tokenize` of `LengthValidator`.
161
-
162
- *Kensuke Naito*
163
-
164
- * Assigning an unknown attribute key to an `ActiveModel` instance during initialization
165
- will now raise `ActiveModel::AttributeAssignment::UnknownAttributeError` instead of
166
- `NoMethodError`.
167
-
168
- Example:
169
-
170
- User.new(foo: 'some value')
171
- # => ActiveModel::AttributeAssignment::UnknownAttributeError: unknown attribute 'foo' for User.
172
-
173
- *Eugene Gilburg*
174
-
175
- * Extracted `ActiveRecord::AttributeAssignment` to `ActiveModel::AttributeAssignment`
176
- allowing to use it for any object as an includable module.
177
-
178
- Example:
179
-
180
- class Cat
181
- include ActiveModel::AttributeAssignment
182
- attr_accessor :name, :status
183
- end
184
-
185
- cat = Cat.new
186
- cat.assign_attributes(name: "Gorby", status: "yawning")
187
- cat.name # => 'Gorby'
188
- cat.status # => 'yawning'
189
- cat.assign_attributes(status: "sleeping")
190
- cat.name # => 'Gorby'
191
- cat.status # => 'sleeping'
192
-
193
- *Bogdan Gusiev*
7
+ * Remove unused `ActiveModel::TestCase` class.
194
8
 
195
- * Add `ActiveModel::Errors#details`
9
+ *Yuji Yaginuma*
196
10
 
197
- To be able to return type of used validator, one can now call `details`
198
- on errors instance.
11
+ * Moved DecimalWithoutScale, Text, and UnsignedInteger from Active Model to Active Record
199
12
 
200
- Example:
13
+ *Iain Beeston*
201
14
 
202
- class User < ActiveRecord::Base
203
- validates :name, presence: true
204
- end
15
+ * Allow indifferent access in `ActiveModel::Errors`.
205
16
 
206
- user = User.new; user.valid?; user.errors.details
207
- => {name: [{error: :blank}]}
17
+ `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
208
18
 
209
- *Wojciech Wnętrzak*
19
+ *Kenichi Kamiya*
210
20
 
211
- * Change `validates_acceptance_of` to accept `true` by default besides `'1'`.
21
+ * Removed deprecated `:tokenizer` in the length validator.
212
22
 
213
- The default for `validates_acceptance_of` is now `'1'` and `true`.
214
- In the past, only `"1"` was the default and you were required to pass
215
- `accept: true` separately.
23
+ *Rafael Mendonça França*
216
24
 
217
- *mokhan*
25
+ * Removed deprecated methods in `ActiveModel::Errors`.
218
26
 
219
- * Remove deprecated `ActiveModel::Dirty#reset_#{attribute}` and
220
- `ActiveModel::Dirty#reset_changes`.
27
+ `#get`, `#set`, `[]=`, `add_on_empty` and `add_on_blank`.
221
28
 
222
29
  *Rafael Mendonça França*
223
30
 
224
- * Change the way in which callback chains can be halted.
225
-
226
- The preferred method to halt a callback chain from now on is to explicitly
227
- `throw(:abort)`.
228
- In the past, returning `false` in an Active Model `before_` callback had
229
- the side effect of halting the callback chain.
230
- This is not recommended anymore and, depending on the value of the
231
- `ActiveSupport.halt_callback_chains_on_return_false` option, will
232
- either not work at all or display a deprecation warning.
233
-
234
- *claudiob*
235
31
 
236
- Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md) for previous changes.
32
+ Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activemodel/CHANGELOG.md) for previous changes.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2004-2016 David Heinemeier Hansson
1
+ Copyright (c) 2004-2017 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
@@ -239,7 +239,7 @@ The latest version of Active Model can be installed with RubyGems:
239
239
 
240
240
  Source code can be downloaded as part of the Rails project on GitHub
241
241
 
242
- * https://github.com/rails/rails/tree/5-0-stable/activemodel
242
+ * https://github.com/rails/rails/tree/master/activemodel
243
243
 
244
244
 
245
245
  == License
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2016 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2017 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -21,37 +21,36 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- require 'active_support'
25
- require 'active_support/rails'
26
- require 'active_model/version'
24
+ require "active_support"
25
+ require "active_support/rails"
26
+ require "active_model/version"
27
27
 
28
28
  module ActiveModel
29
29
  extend ActiveSupport::Autoload
30
30
 
31
31
  autoload :AttributeAssignment
32
32
  autoload :AttributeMethods
33
- autoload :BlockValidator, 'active_model/validator'
33
+ autoload :BlockValidator, "active_model/validator"
34
34
  autoload :Callbacks
35
35
  autoload :Conversion
36
36
  autoload :Dirty
37
- autoload :EachValidator, 'active_model/validator'
37
+ autoload :EachValidator, "active_model/validator"
38
38
  autoload :ForbiddenAttributesProtection
39
39
  autoload :Lint
40
40
  autoload :Model
41
- autoload :Name, 'active_model/naming'
41
+ autoload :Name, "active_model/naming"
42
42
  autoload :Naming
43
43
  autoload :SecurePassword
44
44
  autoload :Serialization
45
- autoload :TestCase
46
45
  autoload :Translation
47
46
  autoload :Validations
48
47
  autoload :Validator
49
48
 
50
49
  eager_autoload do
51
50
  autoload :Errors
52
- autoload :RangeError, 'active_model/errors'
53
- autoload :StrictValidationFailed, 'active_model/errors'
54
- autoload :UnknownAttributeError, 'active_model/errors'
51
+ autoload :RangeError, "active_model/errors"
52
+ autoload :StrictValidationFailed, "active_model/errors"
53
+ autoload :UnknownAttributeError, "active_model/errors"
55
54
  end
56
55
 
57
56
  module Serializers
@@ -69,5 +68,5 @@ module ActiveModel
69
68
  end
70
69
 
71
70
  ActiveSupport.on_load(:i18n) do
72
- I18n.load_path << File.dirname(__FILE__) + '/active_model/locale/en.yml'
71
+ I18n.load_path << File.dirname(__FILE__) + "/active_model/locale/en.yml"
73
72
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/hash/keys'
1
+ require "active_support/core_ext/hash/keys"
2
2
 
3
3
  module ActiveModel
4
4
  module AttributeAssignment
@@ -35,18 +35,18 @@ module ActiveModel
35
35
 
36
36
  private
37
37
 
38
- def _assign_attributes(attributes)
39
- attributes.each do |k, v|
40
- _assign_attribute(k, v)
38
+ def _assign_attributes(attributes)
39
+ attributes.each do |k, v|
40
+ _assign_attribute(k, v)
41
+ end
41
42
  end
42
- end
43
43
 
44
- def _assign_attribute(k, v)
45
- if respond_to?("#{k}=")
46
- public_send("#{k}=", v)
47
- else
48
- raise UnknownAttributeError.new(self, k)
44
+ def _assign_attribute(k, v)
45
+ if respond_to?("#{k}=")
46
+ public_send("#{k}=", v)
47
+ else
48
+ raise UnknownAttributeError.new(self, k)
49
+ end
49
50
  end
50
- end
51
51
  end
52
52
  end
@@ -1,5 +1,5 @@
1
- require 'concurrent/map'
2
- require 'mutex_m'
1
+ require "concurrent/map"
2
+ require "mutex_m"
3
3
 
4
4
  module ActiveModel
5
5
  # Raised when an attribute is not defined.
@@ -289,7 +289,7 @@ module ActiveModel
289
289
  generate_method = "define_method_#{matcher.method_missing_target}"
290
290
 
291
291
  if respond_to?(generate_method, true)
292
- send(generate_method, attr_name)
292
+ send(generate_method, attr_name.to_s)
293
293
  else
294
294
  define_proxy_call true, generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s
295
295
  end
@@ -334,12 +334,11 @@ module ActiveModel
334
334
  }.tap { |mod| include mod }
335
335
  end
336
336
 
337
- protected
338
- def instance_method_already_implemented?(method_name) #:nodoc:
337
+ private
338
+ def instance_method_already_implemented?(method_name)
339
339
  generated_attribute_methods.method_defined?(method_name)
340
340
  end
341
341
 
342
- private
343
342
  # The methods +method_missing+ and +respond_to?+ of this module are
344
343
  # invoked often in a typical rails, both of which invoke the method
345
344
  # +matched_attribute_method+. The latter method iterates through an
@@ -349,11 +348,11 @@ module ActiveModel
349
348
  # used to alleviate the GC, which ultimately also speeds up the app
350
349
  # significantly (in our case our test suite finishes 10% faster with
351
350
  # this cache).
352
- def attribute_method_matchers_cache #:nodoc:
351
+ def attribute_method_matchers_cache
353
352
  @attribute_method_matchers_cache ||= Concurrent::Map.new(initial_capacity: 4)
354
353
  end
355
354
 
356
- def attribute_method_matchers_matching(method_name) #:nodoc:
355
+ def attribute_method_matchers_matching(method_name)
357
356
  attribute_method_matchers_cache.compute_if_absent(method_name) do
358
357
  # Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix
359
358
  # will match every time.
@@ -365,8 +364,8 @@ module ActiveModel
365
364
  # Define a method `name` in `mod` that dispatches to `send`
366
365
  # using the given `extra` args. This falls back on `define_method`
367
366
  # and `send` if the given names cannot be compiled.
368
- def define_proxy_call(include_private, mod, name, send, *extra) #:nodoc:
369
- defn = if name =~ NAME_COMPILABLE_REGEXP
367
+ def define_proxy_call(include_private, mod, name, send, *extra)
368
+ defn = if NAME_COMPILABLE_REGEXP.match?(name)
370
369
  "def #{name}(*args)"
371
370
  else
372
371
  "define_method(:'#{name}') do |*args|"
@@ -374,7 +373,7 @@ module ActiveModel
374
373
 
375
374
  extra = (extra.map!(&:inspect) << "*args").join(", ".freeze)
376
375
 
377
- target = if send =~ CALL_COMPILABLE_REGEXP
376
+ target = if CALL_COMPILABLE_REGEXP.match?(send)
378
377
  "#{"self." unless include_private}#{send}(#{extra})"
379
378
  else
380
379
  "send(:'#{send}', #{extra})"
@@ -393,7 +392,7 @@ module ActiveModel
393
392
  AttributeMethodMatch = Struct.new(:target, :attr_name, :method_name)
394
393
 
395
394
  def initialize(options = {})
396
- @prefix, @suffix = options.fetch(:prefix, ''), options.fetch(:suffix, '')
395
+ @prefix, @suffix = options.fetch(:prefix, ""), options.fetch(:suffix, "")
397
396
  @regex = /^(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})$/
398
397
  @method_missing_target = "#{@prefix}attribute#{@suffix}"
399
398
  @method_name = "#{prefix}%s#{suffix}"
@@ -458,12 +457,11 @@ module ActiveModel
458
457
  end
459
458
  end
460
459
 
461
- protected
462
- def attribute_method?(attr_name) #:nodoc:
460
+ private
461
+ def attribute_method?(attr_name)
463
462
  respond_to_without_attributes?(:attributes) && attributes.include?(attr_name)
464
463
  end
465
464
 
466
- private
467
465
  # Returns a struct representing the matching attribute method.
468
466
  # The struct's attributes are prefix, base and suffix.
469
467
  def matched_attribute_method(method_name)