activemodel 5.0.0.beta3 → 5.0.0.beta4
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 +7 -0
- data/lib/active_model/conversion.rb +2 -2
- data/lib/active_model/dirty.rb +8 -6
- data/lib/active_model/errors.rb +5 -4
- data/lib/active_model/gem_version.rb +1 -1
- data/lib/active_model/type.rb +1 -1
- data/lib/active_model/type/decimal.rb +10 -2
- data/lib/active_model/validations/clusivity.rb +4 -3
- data/lib/active_model/validations/length.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5df9d369a3faa94a6d5fc38b04390262022f27d
|
4
|
+
data.tar.gz: b9ee6b37708667d8d35b8dba1d56ea03f0248384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58760c123352b90b58ec20cc8c1df1e6fcdcb006aed4cebbd91ea679ba3da46bd143616ab1912f2096749144601cc3b50b6eea3a9979ff0e9b75d8bae7598070
|
7
|
+
data.tar.gz: d2003ffd49c49cdd016e7c73aa9d333d10f1c6d261939a1b39b6b7366412bb7c8922a784b3e0272469f7e6d67f821d7c5421d8b7c21b29fbc2224a1fffd73e0b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## Rails 5.0.0.beta4 (April 27, 2016) ##
|
2
|
+
|
3
|
+
* Allow passing record being validated to the message proc to generate
|
4
|
+
customized error messages for that object using I18n helper.
|
5
|
+
|
6
|
+
*Prathamesh Sonpatki*
|
7
|
+
|
1
8
|
## Rails 5.0.0.beta3 (February 24, 2016) ##
|
2
9
|
|
3
10
|
* No changes.
|
@@ -40,8 +40,8 @@ module ActiveModel
|
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
43
|
-
# Returns an Array of all key attributes if any is set,
|
44
|
-
# the object is persisted
|
43
|
+
# Returns an Array of all key attributes if any of the attributes is set, whether or not
|
44
|
+
# the object is persisted. Returns +nil+ if there are no key attributes.
|
45
45
|
#
|
46
46
|
# class Person
|
47
47
|
# include ActiveModel::Conversion
|
data/lib/active_model/dirty.rb
CHANGED
@@ -119,6 +119,9 @@ module ActiveModel
|
|
119
119
|
extend ActiveSupport::Concern
|
120
120
|
include ActiveModel::AttributeMethods
|
121
121
|
|
122
|
+
OPTION_NOT_GIVEN = Object.new # :nodoc:
|
123
|
+
private_constant :OPTION_NOT_GIVEN
|
124
|
+
|
122
125
|
included do
|
123
126
|
attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
|
124
127
|
attribute_method_suffix '_previously_changed?', '_previous_change'
|
@@ -174,11 +177,10 @@ module ActiveModel
|
|
174
177
|
end
|
175
178
|
|
176
179
|
# Handles <tt>*_changed?</tt> for +method_missing+.
|
177
|
-
def attribute_changed?(attr,
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
result
|
180
|
+
def attribute_changed?(attr, from: OPTION_NOT_GIVEN, to: OPTION_NOT_GIVEN) # :nodoc:
|
181
|
+
!!changes_include?(attr) &&
|
182
|
+
(to == OPTION_NOT_GIVEN || to == __send__(attr)) &&
|
183
|
+
(from == OPTION_NOT_GIVEN || from == changed_attributes[attr])
|
182
184
|
end
|
183
185
|
|
184
186
|
# Handles <tt>*_was</tt> for +method_missing+.
|
@@ -187,7 +189,7 @@ module ActiveModel
|
|
187
189
|
end
|
188
190
|
|
189
191
|
# Handles <tt>*_previously_changed?</tt> for +method_missing+.
|
190
|
-
def attribute_previously_changed?(attr
|
192
|
+
def attribute_previously_changed?(attr) #:nodoc:
|
191
193
|
previous_changes_include?(attr)
|
192
194
|
end
|
193
195
|
|
data/lib/active_model/errors.rb
CHANGED
@@ -110,7 +110,7 @@ module ActiveModel
|
|
110
110
|
# person.errors.include?(:name) # => true
|
111
111
|
# person.errors.include?(:age) # => false
|
112
112
|
def include?(attribute)
|
113
|
-
messages[attribute].present?
|
113
|
+
messages.key?(attribute) && messages[attribute].present?
|
114
114
|
end
|
115
115
|
alias :has_key? :include?
|
116
116
|
alias :key? :include?
|
@@ -346,7 +346,7 @@ module ActiveModel
|
|
346
346
|
# # => {:name=>["can't be empty"]}
|
347
347
|
def add_on_empty(attributes, options = {})
|
348
348
|
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
|
349
|
-
ActiveModel::Errors#add_on_empty is deprecated and will be removed in Rails 5.1
|
349
|
+
ActiveModel::Errors#add_on_empty is deprecated and will be removed in Rails 5.1.
|
350
350
|
|
351
351
|
To achieve the same use:
|
352
352
|
|
@@ -368,7 +368,7 @@ module ActiveModel
|
|
368
368
|
# # => {:name=>["can't be blank"]}
|
369
369
|
def add_on_blank(attributes, options = {})
|
370
370
|
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
|
371
|
-
ActiveModel::Errors#add_on_blank is deprecated and will be removed in Rails 5.1
|
371
|
+
ActiveModel::Errors#add_on_blank is deprecated and will be removed in Rails 5.1.
|
372
372
|
|
373
373
|
To achieve the same use:
|
374
374
|
|
@@ -486,7 +486,8 @@ module ActiveModel
|
|
486
486
|
default: defaults,
|
487
487
|
model: @base.model_name.human,
|
488
488
|
attribute: @base.class.human_attribute_name(attribute),
|
489
|
-
value: value
|
489
|
+
value: value,
|
490
|
+
object: @base
|
490
491
|
}.merge!(options)
|
491
492
|
|
492
493
|
I18n.translate(key, options)
|
data/lib/active_model/type.rb
CHANGED
@@ -47,7 +47,7 @@ module ActiveModel
|
|
47
47
|
register(:binary, Type::Binary)
|
48
48
|
register(:boolean, Type::Boolean)
|
49
49
|
register(:date, Type::Date)
|
50
|
-
register(:
|
50
|
+
register(:datetime, Type::DateTime)
|
51
51
|
register(:decimal, Type::Decimal)
|
52
52
|
register(:float, Type::Float)
|
53
53
|
register(:immutable_string, Type::ImmutableString)
|
@@ -29,12 +29,12 @@ module ActiveModel
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
apply_scale(casted_value)
|
33
33
|
end
|
34
34
|
|
35
35
|
def convert_float_to_big_decimal(value)
|
36
36
|
if precision
|
37
|
-
BigDecimal(value, float_precision)
|
37
|
+
BigDecimal(apply_scale(value), float_precision)
|
38
38
|
else
|
39
39
|
value.to_d
|
40
40
|
end
|
@@ -47,6 +47,14 @@ module ActiveModel
|
|
47
47
|
precision.to_i
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
def apply_scale(value)
|
52
|
+
if scale
|
53
|
+
value.round(scale)
|
54
|
+
else
|
55
|
+
value
|
56
|
+
end
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
@@ -30,14 +30,15 @@ module ActiveModel
|
|
30
30
|
@delimiter ||= options[:in] || options[:within]
|
31
31
|
end
|
32
32
|
|
33
|
-
# In Ruby
|
33
|
+
# In Ruby 2.2 <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all
|
34
34
|
# possible values in the range for equality, which is slower but more accurate.
|
35
35
|
# <tt>Range#cover?</tt> uses the previous logic of comparing a value with the range
|
36
|
-
# endpoints, which is fast but is only accurate on Numeric, Time,
|
36
|
+
# endpoints, which is fast but is only accurate on Numeric, Time, Date,
|
37
|
+
# or DateTime ranges.
|
37
38
|
def inclusion_method(enumerable)
|
38
39
|
if enumerable.is_a? Range
|
39
40
|
case enumerable.first
|
40
|
-
when Numeric, Time, DateTime
|
41
|
+
when Numeric, Time, DateTime, Date
|
41
42
|
:cover?
|
42
43
|
else
|
43
44
|
:include?
|
@@ -136,7 +136,7 @@ module ActiveModel
|
|
136
136
|
# * <tt>:too_long</tt> - The error message if the attribute goes over the
|
137
137
|
# maximum (default is: "is too long (maximum is %{count} characters)").
|
138
138
|
# * <tt>:too_short</tt> - The error message if the attribute goes under the
|
139
|
-
# minimum (default is: "is too short (
|
139
|
+
# minimum (default is: "is too short (minimum is %{count} characters)").
|
140
140
|
# * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt>
|
141
141
|
# method and the attribute is the wrong size (default is: "is the wrong
|
142
142
|
# length (should be %{count} characters)").
|
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: 5.0.0.
|
4
|
+
version: 5.0.0.beta4
|
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: 2016-
|
11
|
+
date: 2016-04-27 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: 5.0.0.
|
19
|
+
version: 5.0.0.beta4
|
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: 5.0.0.
|
26
|
+
version: 5.0.0.beta4
|
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.
|
@@ -93,7 +93,7 @@ files:
|
|
93
93
|
- lib/active_model/validations/with.rb
|
94
94
|
- lib/active_model/validator.rb
|
95
95
|
- lib/active_model/version.rb
|
96
|
-
homepage: http://
|
96
|
+
homepage: http://rubyonrails.org
|
97
97
|
licenses:
|
98
98
|
- MIT
|
99
99
|
metadata: {}
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: 1.3.1
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.6.4
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: A toolkit for building modeling frameworks (part of Rails).
|