activemodel 5.2.2 → 5.2.4.5

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
  SHA256:
3
- metadata.gz: c2dc37010b3f3be02dca09a02b927f4b545b6779326999303d128bb565a2eace
4
- data.tar.gz: 78c5f9fee07954bcce62e551ed1172a8fcb445d37b92cbbb215e30593d3e7dfa
3
+ metadata.gz: d36092c1b99284275961af3ad57af797842b10db345a47cbbfc8bb98729bcbef
4
+ data.tar.gz: 0fff19824645d82690696ce9a92c8d2503bcf278b59297ca8c098780a35a818f
5
5
  SHA512:
6
- metadata.gz: e4a244c495ed22f57b370d30195a23dbc0c245de901ecd6069f7175d10e641101f47e0843b045ad0b96e2b96d738594d8068bfba2d80cfa18d78a1855747e81f
7
- data.tar.gz: 7e1efba879c6baee414edd02508521d92a25ed16462360e55e27132ea866eba1f867ed6dd117a059ef5fa87f1010661e32a3727db9a61a453344100889ec02fc
6
+ metadata.gz: ada5cec1cb36da2223c0a772e8150b65859fa4735e4b4ba8d88c7fb848b0496cdcb827b128c07fd05e5d47ea8632b1f96aca24e6b27b2097be6e4c06915a6c21
7
+ data.tar.gz: 9a591a616fff0a1cb4f054d239d105ac62edbe3b9845a6ddcd9c3363b78a3ff36f9b5f74aa502ebd3c64d186ac4c9923461e887a4c4a48654550df4557de3cc7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,62 @@
1
+ ## Rails 5.2.4.5 (February 10, 2021) ##
2
+
3
+ * No changes.
4
+
5
+
6
+ ## Rails 5.2.4.4 (September 09, 2020) ##
7
+
8
+ * No changes.
9
+
10
+
11
+ ## Rails 5.2.4.3 (May 18, 2020) ##
12
+
13
+ * No changes.
14
+
15
+
16
+ ## Rails 5.2.4.1 (December 18, 2019) ##
17
+
18
+ * No changes.
19
+
20
+
21
+ ## Rails 5.2.4 (November 27, 2019) ##
22
+
23
+ * Type cast falsy boolean symbols on boolean attribute as false.
24
+
25
+ Fixes #35676.
26
+
27
+ *Ryuta Kamizono*
28
+
29
+
30
+ ## Rails 5.2.3 (March 27, 2019) ##
31
+
32
+ * Fix date value when casting a multiparameter date hash to not convert
33
+ from Gregorian date to Julian date.
34
+
35
+ Before:
36
+
37
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
38
+ => #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
39
+
40
+ After:
41
+
42
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
43
+ => #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
44
+
45
+ Fixes #28521.
46
+
47
+ *Sayan Chakraborty*
48
+
49
+ * Fix numericality equality validation of `BigDecimal` and `Float`
50
+ by casting to `BigDecimal` on both ends of the validation.
51
+
52
+ *Gannon McGibbon*
53
+
54
+
55
+ ## Rails 5.2.2.1 (March 11, 2019) ##
56
+
57
+ * No changes.
58
+
59
+
1
60
  ## Rails 5.2.2 (December 04, 2018) ##
2
61
 
3
62
  * Fix numericality validator to still use value before type cast except Active Record.
@@ -9,8 +9,8 @@ module ActiveModel
9
9
  module VERSION
10
10
  MAJOR = 5
11
11
  MINOR = 2
12
- TINY = 2
13
- PRE = nil
12
+ TINY = 4
13
+ PRE = "5"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -14,7 +14,16 @@ module ActiveModel
14
14
  # - Empty strings are coerced to +nil+
15
15
  # - All other values will be coerced to +true+
16
16
  class Boolean < Value
17
- FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"].to_set
17
+ FALSE_VALUES = [
18
+ false, 0,
19
+ "0", :"0",
20
+ "f", :f,
21
+ "F", :F,
22
+ "false", :false,
23
+ "FALSE", :FALSE,
24
+ "off", :off,
25
+ "OFF", :OFF,
26
+ ].to_set.freeze
18
27
 
19
28
  def type # :nodoc:
20
29
  :boolean
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class Date < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::AcceptsMultiparameterTime.new
7
8
 
8
9
  def type
@@ -49,7 +50,7 @@ module ActiveModel
49
50
 
50
51
  def value_from_multiparameter_assignment(*)
51
52
  time = super
52
- time && time.to_date
53
+ time && new_date(time.year, time.mon, time.mday)
53
54
  end
54
55
  end
55
56
  end
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class DateTime < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::TimeValue
7
8
  include Helpers::AcceptsMultiparameterTime.new(
8
9
  defaults: { 4 => 0, 5 => 0 }
@@ -4,3 +4,4 @@ require "active_model/type/helpers/accepts_multiparameter_time"
4
4
  require "active_model/type/helpers/numeric"
5
5
  require "active_model/type/helpers/mutable"
6
6
  require "active_model/type/helpers/time_value"
7
+ require "active_model/type/helpers/timezone"
@@ -21,18 +21,6 @@ module ActiveModel
21
21
  value
22
22
  end
23
23
 
24
- def is_utc?
25
- ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC"
26
- end
27
-
28
- def default_timezone
29
- if is_utc?
30
- :utc
31
- else
32
- :local
33
- end
34
- end
35
-
36
24
  def apply_seconds_precision(value)
37
25
  return value unless precision && value.respond_to?(:usec)
38
26
  number_of_insignificant_digits = 6 - precision
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/time/zones"
4
+
5
+ module ActiveModel
6
+ module Type
7
+ module Helpers # :nodoc: all
8
+ module Timezone
9
+ def is_utc?
10
+ ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC"
11
+ end
12
+
13
+ def default_timezone
14
+ is_utc? ? :utc : :local
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class Time < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::TimeValue
7
8
  include Helpers::AcceptsMultiparameterTime.new(
8
9
  defaults: { 1 => 1970, 2 => 1, 3 => 1, 4 => 0, 5 => 0 }
@@ -12,6 +13,10 @@ module ActiveModel
12
13
  :time
13
14
  end
14
15
 
16
+ def serialize(value)
17
+ super(cast(value))
18
+ end
19
+
15
20
  def user_input_in_time_zone(value)
16
21
  return unless value.present?
17
22
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bigdecimal/util"
4
+
3
5
  module ActiveModel
4
6
  module Validations
5
7
  class NumericalityValidator < EachValidator # :nodoc:
@@ -9,6 +11,8 @@ module ActiveModel
9
11
 
10
12
  RESERVED_OPTIONS = CHECKS.keys + [:only_integer]
11
13
 
14
+ INTEGER_REGEX = /\A[+-]?\d+\z/
15
+
12
16
  def check_validity!
13
17
  keys = CHECKS.keys - [:odd, :even]
14
18
  options.slice(*keys).each do |option, value|
@@ -49,11 +53,7 @@ module ActiveModel
49
53
  return
50
54
  end
51
55
 
52
- if raw_value.is_a?(Numeric)
53
- value = raw_value
54
- else
55
- value = parse_raw_value_as_a_number(raw_value)
56
- end
56
+ value = parse_as_number(raw_value)
57
57
 
58
58
  options.slice(*CHECKS.keys).each do |option, option_value|
59
59
  case option
@@ -69,6 +69,8 @@ module ActiveModel
69
69
  option_value = record.send(option_value)
70
70
  end
71
71
 
72
+ option_value = parse_as_number(option_value)
73
+
72
74
  unless value.send(CHECKS[option], option_value)
73
75
  record.errors.add(attr_name, option, filtered_options(value).merge!(count: option_value))
74
76
  end
@@ -79,22 +81,29 @@ module ActiveModel
79
81
  private
80
82
 
81
83
  def is_number?(raw_value)
82
- !parse_raw_value_as_a_number(raw_value).nil?
84
+ !parse_as_number(raw_value).nil?
83
85
  rescue ArgumentError, TypeError
84
86
  false
85
87
  end
86
88
 
87
- def parse_raw_value_as_a_number(raw_value)
88
- return raw_value.to_i if is_integer?(raw_value)
89
- Kernel.Float(raw_value) unless is_hexadecimal_literal?(raw_value)
89
+ def parse_as_number(raw_value)
90
+ if raw_value.is_a?(Float)
91
+ raw_value.to_d
92
+ elsif raw_value.is_a?(Numeric)
93
+ raw_value
94
+ elsif is_integer?(raw_value)
95
+ raw_value.to_i
96
+ elsif !is_hexadecimal_literal?(raw_value)
97
+ Kernel.Float(raw_value).to_d
98
+ end
90
99
  end
91
100
 
92
101
  def is_integer?(raw_value)
93
- /\A[+-]?\d+\z/ === raw_value.to_s
102
+ INTEGER_REGEX === raw_value.to_s
94
103
  end
95
104
 
96
105
  def is_hexadecimal_literal?(raw_value)
97
- /\A0[xX]/ === raw_value
106
+ /\A0[xX]/ === raw_value.to_s
98
107
  end
99
108
 
100
109
  def filtered_options(value)
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.2.2
4
+ version: 5.2.4.5
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: 2018-12-04 00:00:00.000000000 Z
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: 5.2.2
19
+ version: 5.2.4.5
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.2.2
26
+ version: 5.2.4.5
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.
@@ -73,6 +73,7 @@ files:
73
73
  - lib/active_model/type/helpers/mutable.rb
74
74
  - lib/active_model/type/helpers/numeric.rb
75
75
  - lib/active_model/type/helpers/time_value.rb
76
+ - lib/active_model/type/helpers/timezone.rb
76
77
  - lib/active_model/type/immutable_string.rb
77
78
  - lib/active_model/type/integer.rb
78
79
  - lib/active_model/type/registry.rb
@@ -100,8 +101,8 @@ homepage: http://rubyonrails.org
100
101
  licenses:
101
102
  - MIT
102
103
  metadata:
103
- source_code_uri: https://github.com/rails/rails/tree/v5.2.2/activemodel
104
- changelog_uri: https://github.com/rails/rails/blob/v5.2.2/activemodel/CHANGELOG.md
104
+ source_code_uri: https://github.com/rails/rails/tree/v5.2.4.5/activemodel
105
+ changelog_uri: https://github.com/rails/rails/blob/v5.2.4.5/activemodel/CHANGELOG.md
105
106
  post_install_message:
106
107
  rdoc_options: []
107
108
  require_paths:
@@ -117,8 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.7.6
121
+ rubygems_version: 3.0.3
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: A toolkit for building modeling frameworks (part of Rails).