activemodel 5.0.0.beta3 → 5.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c283ac88f7c8c09878346cd9ac5317371c141bb6
4
- data.tar.gz: 9141a1af7e5100d957d9192e0e2beae4306e2c68
3
+ metadata.gz: a5df9d369a3faa94a6d5fc38b04390262022f27d
4
+ data.tar.gz: b9ee6b37708667d8d35b8dba1d56ea03f0248384
5
5
  SHA512:
6
- metadata.gz: 069aec401e7854c4d2e3e578ed6d4226f07d9411049b262ef1d5a81ab639c9d34aff29e22af5676a0ec065b98a4ef9e0cf5b31c2d228aff833d70465de61cf21
7
- data.tar.gz: a4e7860c438a2ac4933cdada88fe0e84c0154870ec7fbd88f60d6b53f1d4c3e1824ac494f7f54871c9bd7b72f299890b9c2c5efdbf1f937e68297ddd0c9ec26b
6
+ metadata.gz: 58760c123352b90b58ec20cc8c1df1e6fcdcb006aed4cebbd91ea679ba3da46bd143616ab1912f2096749144601cc3b50b6eea3a9979ff0e9b75d8bae7598070
7
+ data.tar.gz: d2003ffd49c49cdd016e7c73aa9d333d10f1c6d261939a1b39b6b7366412bb7c8922a784b3e0272469f7e6d67f821d7c5421d8b7c21b29fbc2224a1fffd73e0b
@@ -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, regardless if
44
- # the object is persisted or not. Returns +nil+ if there are no key attributes.
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
@@ -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, options = {}) #:nodoc:
178
- result = changes_include?(attr)
179
- result &&= options[:to] == __send__(attr) if options.key?(:to)
180
- result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
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, options = {}) #:nodoc:
192
+ def attribute_previously_changed?(attr) #:nodoc:
191
193
  previous_changes_include?(attr)
192
194
  end
193
195
 
@@ -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)
@@ -8,7 +8,7 @@ module ActiveModel
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "beta3"
11
+ PRE = "beta4"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -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(:date_time, Type::DateTime)
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
- scale ? casted_value.round(scale) : casted_value
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 1.9 <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all
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, or DateTime ranges.
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 (min is %{count} characters)").
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.beta3
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-02-24 00:00:00.000000000 Z
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.beta3
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.beta3
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://www.rubyonrails.org
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.5.1
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).