activemodel 6.1.0.rc1 → 6.1.2.1
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 +16 -1
- data/README.rdoc +1 -1
- data/lib/active_model/attribute.rb +4 -4
- data/lib/active_model/attributes.rb +1 -1
- data/lib/active_model/callbacks.rb +1 -1
- data/lib/active_model/gem_version.rb +2 -2
- data/lib/active_model/validations.rb +4 -4
- data/lib/active_model/validations/callbacks.rb +15 -15
- data/lib/active_model/validations/numericality.rb +10 -4
- data/lib/active_model/validator.rb +4 -3
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d22a81303a51bc00eeb70780931f1c16fcc625f36b1bee7d7f3bbb28a29dd85
|
4
|
+
data.tar.gz: aa65068c74788cf1db46b47dfbe9dcd78f28fb9577e00c627da6e9c0727477ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7343297298be5f16edcc6c003b5133ca44252e80bde9c319bbb88059af5d3dc89eca6c5e0214df43a835a31ebc8901688c999d690211b79c04aef618b44fe7e1
|
7
|
+
data.tar.gz: 53d4aa8fcee379988cc5d01d12b6908794a04757162516d8f1256096016a149b119e0aec6e5f1fd1d37fe695b3fce2033fab9911afbece19c70ab451d21cd03d
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
## Rails 6.1.
|
1
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
2
|
+
|
3
|
+
* No changes.
|
4
|
+
|
5
|
+
|
6
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
7
|
+
|
8
|
+
* No changes.
|
9
|
+
|
10
|
+
|
11
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
12
|
+
|
13
|
+
* No changes.
|
14
|
+
|
15
|
+
|
16
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
2
17
|
|
3
18
|
* Pass in `base` instead of `base_class` to Error.human_attribute_name
|
4
19
|
|
data/README.rdoc
CHANGED
@@ -241,7 +241,7 @@ The latest version of Active Model can be installed with RubyGems:
|
|
241
241
|
|
242
242
|
Source code can be downloaded as part of the Rails project on GitHub
|
243
243
|
|
244
|
-
* https://github.com/rails/rails/tree/
|
244
|
+
* https://github.com/rails/rails/tree/main/activemodel
|
245
245
|
|
246
246
|
|
247
247
|
== License
|
@@ -164,10 +164,10 @@ module ActiveModel
|
|
164
164
|
type.deserialize(value)
|
165
165
|
end
|
166
166
|
|
167
|
-
|
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:
|
@@ -147,7 +147,7 @@ module ActiveModel
|
|
147
147
|
conditional = ActiveSupport::Callbacks::Conditionals::Value.new { |v|
|
148
148
|
v != false
|
149
149
|
}
|
150
|
-
options[:if] = Array(options[:if])
|
150
|
+
options[:if] = Array(options[:if]) + [conditional]
|
151
151
|
set_callback(:"#{callback}", :after, *args, options, &block)
|
152
152
|
end
|
153
153
|
end
|
@@ -163,10 +163,10 @@ module ActiveModel
|
|
163
163
|
if options.key?(:on)
|
164
164
|
options = options.dup
|
165
165
|
options[:on] = Array(options[:on])
|
166
|
-
options[:if] =
|
167
|
-
|
168
|
-
|
169
|
-
|
166
|
+
options[:if] = [
|
167
|
+
->(o) { !(options[:on] & Array(o.validation_context)).empty? },
|
168
|
+
*options[:if]
|
169
|
+
]
|
170
170
|
end
|
171
171
|
|
172
172
|
set_callback(:validate, *args, options, &block)
|
@@ -56,14 +56,7 @@ module ActiveModel
|
|
56
56
|
def before_validation(*args, &block)
|
57
57
|
options = args.extract_options!
|
58
58
|
|
59
|
-
|
60
|
-
options = options.dup
|
61
|
-
options[:on] = Array(options[:on])
|
62
|
-
options[:if] = Array(options[:if])
|
63
|
-
options[:if].unshift ->(o) {
|
64
|
-
!(options[:on] & Array(o.validation_context)).empty?
|
65
|
-
}
|
66
|
-
end
|
59
|
+
set_options_for_callback(options)
|
67
60
|
|
68
61
|
set_callback(:validation, :before, *args, options, &block)
|
69
62
|
end
|
@@ -99,16 +92,23 @@ module ActiveModel
|
|
99
92
|
options = options.dup
|
100
93
|
options[:prepend] = true
|
101
94
|
|
102
|
-
|
103
|
-
options[:on] = Array(options[:on])
|
104
|
-
options[:if] = Array(options[:if])
|
105
|
-
options[:if].unshift ->(o) {
|
106
|
-
!(options[:on] & Array(o.validation_context)).empty?
|
107
|
-
}
|
108
|
-
end
|
95
|
+
set_options_for_callback(options)
|
109
96
|
|
110
97
|
set_callback(:validation, :after, *args, options, &block)
|
111
98
|
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def set_options_for_callback(options)
|
102
|
+
if options.key?(:on)
|
103
|
+
options[:on] = Array(options[:on])
|
104
|
+
options[:if] = [
|
105
|
+
->(o) {
|
106
|
+
!(options[:on] & Array(o.validation_context)).empty?
|
107
|
+
},
|
108
|
+
*options[:if]
|
109
|
+
]
|
110
|
+
end
|
111
|
+
end
|
112
112
|
end
|
113
113
|
|
114
114
|
private
|
@@ -64,6 +64,8 @@ module ActiveModel
|
|
64
64
|
def parse_as_number(raw_value, precision, scale)
|
65
65
|
if raw_value.is_a?(Float)
|
66
66
|
parse_float(raw_value, precision, scale)
|
67
|
+
elsif raw_value.is_a?(BigDecimal)
|
68
|
+
round(raw_value, scale)
|
67
69
|
elsif raw_value.is_a?(Numeric)
|
68
70
|
raw_value
|
69
71
|
elsif is_integer?(raw_value)
|
@@ -74,7 +76,11 @@ module ActiveModel
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def parse_float(raw_value, precision, scale)
|
77
|
-
(
|
79
|
+
round(raw_value, scale).to_d(precision)
|
80
|
+
end
|
81
|
+
|
82
|
+
def round(raw_value, scale)
|
83
|
+
scale ? raw_value.round(scale) : raw_value
|
78
84
|
end
|
79
85
|
|
80
86
|
def is_number?(raw_value, precision, scale)
|
@@ -108,8 +114,8 @@ module ActiveModel
|
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
111
|
-
def
|
112
|
-
return
|
117
|
+
def prepare_value_for_validation(value, record, attr_name)
|
118
|
+
return value if record_attribute_changed_in_place?(record, attr_name)
|
113
119
|
|
114
120
|
came_from_user = :"#{attr_name}_came_from_user?"
|
115
121
|
|
@@ -126,7 +132,7 @@ module ActiveModel
|
|
126
132
|
end
|
127
133
|
end
|
128
134
|
|
129
|
-
raw_value ||
|
135
|
+
raw_value || value
|
130
136
|
end
|
131
137
|
|
132
138
|
def record_attribute_changed_in_place?(record, attr_name)
|
@@ -147,8 +147,9 @@ module ActiveModel
|
|
147
147
|
# override +validate_each+ with validation logic.
|
148
148
|
def validate(record)
|
149
149
|
attributes.each do |attribute|
|
150
|
-
value = read_attribute_for_validation(
|
150
|
+
value = record.read_attribute_for_validation(attribute)
|
151
151
|
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
|
152
|
+
value = prepare_value_for_validation(value, record, attribute)
|
152
153
|
validate_each(record, attribute, value)
|
153
154
|
end
|
154
155
|
end
|
@@ -166,8 +167,8 @@ module ActiveModel
|
|
166
167
|
end
|
167
168
|
|
168
169
|
private
|
169
|
-
def
|
170
|
-
|
170
|
+
def prepare_value_for_validation(value, record, attr_name)
|
171
|
+
value
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.
|
4
|
+
version: 6.1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.1.
|
19
|
+
version: 6.1.2.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.1.
|
26
|
+
version: 6.1.2.1
|
27
27
|
description: A toolkit for building modeling frameworks like Active Record. Rich support
|
28
28
|
for attributes, callbacks, validations, serialization, internationalization, and
|
29
29
|
testing.
|
@@ -104,10 +104,10 @@ licenses:
|
|
104
104
|
- MIT
|
105
105
|
metadata:
|
106
106
|
bug_tracker_uri: https://github.com/rails/rails/issues
|
107
|
-
changelog_uri: https://github.com/rails/rails/blob/v6.1.
|
108
|
-
documentation_uri: https://api.rubyonrails.org/v6.1.
|
107
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.1.2.1/activemodel/CHANGELOG.md
|
108
|
+
documentation_uri: https://api.rubyonrails.org/v6.1.2.1/
|
109
109
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
110
|
-
source_code_uri: https://github.com/rails/rails/tree/v6.1.
|
110
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.1.2.1/activemodel
|
111
111
|
post_install_message:
|
112
112
|
rdoc_options: []
|
113
113
|
require_paths:
|
@@ -119,11 +119,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: 2.5.0
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.0.3
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: A toolkit for building modeling frameworks (part of Rails).
|