activemodel 5.2.3.rc1 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -84
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_model.rb +1 -1
- data/lib/active_model/attribute.rb +3 -4
- data/lib/active_model/attribute/user_provided_default.rb +1 -2
- data/lib/active_model/attribute_assignment.rb +1 -1
- data/lib/active_model/attribute_methods.rb +39 -1
- data/lib/active_model/attribute_mutation_tracker.rb +1 -6
- data/lib/active_model/attribute_set.rb +2 -10
- data/lib/active_model/attribute_set/builder.rb +1 -3
- data/lib/active_model/attribute_set/yaml_encoder.rb +1 -2
- data/lib/active_model/attributes.rb +10 -22
- data/lib/active_model/callbacks.rb +10 -7
- data/lib/active_model/conversion.rb +1 -1
- data/lib/active_model/dirty.rb +2 -2
- data/lib/active_model/errors.rb +90 -11
- data/lib/active_model/gem_version.rb +4 -4
- data/lib/active_model/naming.rb +19 -3
- data/lib/active_model/railtie.rb +6 -0
- data/lib/active_model/secure_password.rb +48 -55
- data/lib/active_model/serializers/json.rb +10 -9
- data/lib/active_model/type/binary.rb +1 -1
- data/lib/active_model/type/date.rb +1 -2
- data/lib/active_model/type/date_time.rb +3 -4
- data/lib/active_model/type/decimal.rb +4 -0
- data/lib/active_model/type/helpers.rb +0 -1
- data/lib/active_model/type/helpers/time_value.rb +19 -1
- data/lib/active_model/type/integer.rb +1 -6
- data/lib/active_model/type/registry.rb +2 -10
- data/lib/active_model/type/string.rb +2 -2
- data/lib/active_model/type/time.rb +0 -5
- data/lib/active_model/validations.rb +0 -2
- data/lib/active_model/validations/acceptance.rb +4 -8
- data/lib/active_model/validations/clusivity.rb +1 -1
- data/lib/active_model/validations/confirmation.rb +2 -2
- data/lib/active_model/validations/inclusion.rb +1 -1
- data/lib/active_model/validations/numericality.rb +9 -6
- data/lib/active_model/validations/validates.rb +2 -2
- data/lib/active_model/validator.rb +1 -1
- metadata +7 -8
- data/lib/active_model/type/helpers/timezone.rb +0 -19
@@ -3,7 +3,6 @@
|
|
3
3
|
module ActiveModel
|
4
4
|
module Type
|
5
5
|
class Date < Value # :nodoc:
|
6
|
-
include Helpers::Timezone
|
7
6
|
include Helpers::AcceptsMultiparameterTime.new
|
8
7
|
|
9
8
|
def type
|
@@ -50,7 +49,7 @@ module ActiveModel
|
|
50
49
|
|
51
50
|
def value_from_multiparameter_assignment(*)
|
52
51
|
time = super
|
53
|
-
time &&
|
52
|
+
time && time.to_date
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module ActiveModel
|
4
4
|
module Type
|
5
5
|
class DateTime < Value # :nodoc:
|
6
|
-
include Helpers::Timezone
|
7
6
|
include Helpers::TimeValue
|
8
7
|
include Helpers::AcceptsMultiparameterTime.new(
|
9
8
|
defaults: { 4 => 0, 5 => 0 }
|
@@ -40,9 +39,9 @@ module ActiveModel
|
|
40
39
|
end
|
41
40
|
|
42
41
|
def value_from_multiparameter_assignment(values_hash)
|
43
|
-
|
44
|
-
if
|
45
|
-
raise ArgumentError,
|
42
|
+
missing_parameters = (1..3).select { |key| !values_hash.key?(key) }
|
43
|
+
if missing_parameters.any?
|
44
|
+
raise ArgumentError, "Provided hash #{values_hash} doesn't contain necessary keys: #{missing_parameters}"
|
46
45
|
end
|
47
46
|
super
|
48
47
|
end
|
@@ -21,6 +21,18 @@ 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
|
+
|
24
36
|
def apply_seconds_precision(value)
|
25
37
|
return value unless precision && value.respond_to?(:usec)
|
26
38
|
number_of_insignificant_digits = 6 - precision
|
@@ -58,7 +70,13 @@ module ActiveModel
|
|
58
70
|
# Doesn't handle time zones.
|
59
71
|
def fast_string_to_time(string)
|
60
72
|
if string =~ ISO_DATETIME
|
61
|
-
|
73
|
+
microsec_part = $7
|
74
|
+
if microsec_part && microsec_part.start_with?(".") && microsec_part.length == 7
|
75
|
+
microsec_part[0] = ""
|
76
|
+
microsec = microsec_part.to_i
|
77
|
+
else
|
78
|
+
microsec = (microsec_part.to_r * 1_000_000).to_i
|
79
|
+
end
|
62
80
|
new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
|
63
81
|
end
|
64
82
|
end
|
@@ -31,13 +31,8 @@ module ActiveModel
|
|
31
31
|
result
|
32
32
|
end
|
33
33
|
|
34
|
-
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
35
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
36
|
-
protected
|
37
|
-
|
38
|
-
attr_reader :range
|
39
|
-
|
40
34
|
private
|
35
|
+
attr_reader :range
|
41
36
|
|
42
37
|
def cast_value(value)
|
43
38
|
case value
|
@@ -23,13 +23,8 @@ module ActiveModel
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
27
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
28
|
-
protected
|
29
|
-
|
30
|
-
attr_reader :registrations
|
31
|
-
|
32
26
|
private
|
27
|
+
attr_reader :registrations
|
33
28
|
|
34
29
|
def registration_klass
|
35
30
|
Registration
|
@@ -59,10 +54,7 @@ module ActiveModel
|
|
59
54
|
type_name == name
|
60
55
|
end
|
61
56
|
|
62
|
-
|
63
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
64
|
-
protected
|
65
|
-
|
57
|
+
private
|
66
58
|
attr_reader :name, :block
|
67
59
|
end
|
68
60
|
end
|
@@ -3,7 +3,6 @@
|
|
3
3
|
module ActiveModel
|
4
4
|
module Type
|
5
5
|
class Time < Value # :nodoc:
|
6
|
-
include Helpers::Timezone
|
7
6
|
include Helpers::TimeValue
|
8
7
|
include Helpers::AcceptsMultiparameterTime.new(
|
9
8
|
defaults: { 1 => 1970, 2 => 1, 3 => 1, 4 => 0, 5 => 0 }
|
@@ -13,10 +12,6 @@ module ActiveModel
|
|
13
12
|
:time
|
14
13
|
end
|
15
14
|
|
16
|
-
def serialize(value)
|
17
|
-
super(cast(value))
|
18
|
-
end
|
19
|
-
|
20
15
|
def user_input_in_time_zone(value)
|
21
16
|
return unless value.present?
|
22
17
|
|
@@ -54,17 +54,13 @@ module ActiveModel
|
|
54
54
|
def define_on(klass)
|
55
55
|
attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
|
56
56
|
attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
|
57
|
-
klass.
|
58
|
-
klass.
|
57
|
+
klass.define_attribute_methods
|
58
|
+
klass.attr_reader(*attr_readers)
|
59
|
+
klass.attr_writer(*attr_writers)
|
59
60
|
end
|
60
61
|
|
61
|
-
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
62
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
63
|
-
protected
|
64
|
-
|
65
|
-
attr_reader :attributes
|
66
|
-
|
67
62
|
private
|
63
|
+
attr_reader :attributes
|
68
64
|
|
69
65
|
def convert_to_reader_name(method_name)
|
70
66
|
method_name.to_s.chomp("=")
|
@@ -32,7 +32,7 @@ module ActiveModel
|
|
32
32
|
@delimiter ||= options[:in] || options[:within]
|
33
33
|
end
|
34
34
|
|
35
|
-
#
|
35
|
+
# After Ruby 2.2, <tt>Range#include?</tt> on non-number-or-time-ish ranges checks all
|
36
36
|
# possible values in the range for equality, which is slower but more accurate.
|
37
37
|
# <tt>Range#cover?</tt> uses the previous logic of comparing a value with the range
|
38
38
|
# endpoints, which is fast but is only accurate on Numeric, Time, Date,
|
@@ -19,11 +19,11 @@ module ActiveModel
|
|
19
19
|
|
20
20
|
private
|
21
21
|
def setup!(klass)
|
22
|
-
klass.
|
22
|
+
klass.attr_reader(*attributes.map do |attribute|
|
23
23
|
:"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation")
|
24
24
|
end.compact)
|
25
25
|
|
26
|
-
klass.
|
26
|
+
klass.attr_writer(*attributes.map do |attribute|
|
27
27
|
:"#{attribute}_confirmation" unless klass.method_defined?(:"#{attribute}_confirmation=")
|
28
28
|
end.compact)
|
29
29
|
end
|
@@ -19,7 +19,7 @@ module ActiveModel
|
|
19
19
|
# particular enumerable object.
|
20
20
|
#
|
21
21
|
# class Person < ActiveRecord::Base
|
22
|
-
# validates_inclusion_of :
|
22
|
+
# validates_inclusion_of :role, in: %w( admin contributor )
|
23
23
|
# validates_inclusion_of :age, in: 0..99
|
24
24
|
# validates_inclusion_of :format, in: %w( jpg gif png ), message: "extension %{value} is not included in the list"
|
25
25
|
# validates_inclusion_of :states, in: ->(person) { STATES[person.country] }
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "bigdecimal/util"
|
4
|
-
|
5
3
|
module ActiveModel
|
6
4
|
module Validations
|
7
5
|
class NumericalityValidator < EachValidator # :nodoc:
|
@@ -12,6 +10,7 @@ module ActiveModel
|
|
12
10
|
RESERVED_OPTIONS = CHECKS.keys + [:only_integer]
|
13
11
|
|
14
12
|
INTEGER_REGEX = /\A[+-]?\d+\z/
|
13
|
+
DECIMAL_REGEX = /\A[+-]?\d+\.?\d*(e|e[+-])?\d+\z/
|
15
14
|
|
16
15
|
def check_validity!
|
17
16
|
keys = CHECKS.keys - [:odd, :even]
|
@@ -93,17 +92,21 @@ module ActiveModel
|
|
93
92
|
raw_value
|
94
93
|
elsif is_integer?(raw_value)
|
95
94
|
raw_value.to_i
|
96
|
-
elsif !is_hexadecimal_literal?(raw_value)
|
97
|
-
|
95
|
+
elsif is_decimal?(raw_value) && !is_hexadecimal_literal?(raw_value)
|
96
|
+
BigDecimal(raw_value)
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
100
|
def is_integer?(raw_value)
|
102
|
-
INTEGER_REGEX
|
101
|
+
INTEGER_REGEX.match?(raw_value.to_s)
|
102
|
+
end
|
103
|
+
|
104
|
+
def is_decimal?(raw_value)
|
105
|
+
DECIMAL_REGEX.match?(raw_value.to_s)
|
103
106
|
end
|
104
107
|
|
105
108
|
def is_hexadecimal_literal?(raw_value)
|
106
|
-
/\A0[xX]
|
109
|
+
/\A0[xX]/.match?(raw_value)
|
107
110
|
end
|
108
111
|
|
109
112
|
def filtered_options(value)
|
@@ -63,7 +63,7 @@ module ActiveModel
|
|
63
63
|
# and strings in shortcut form.
|
64
64
|
#
|
65
65
|
# validates :email, format: /@/
|
66
|
-
# validates :
|
66
|
+
# validates :role, inclusion: %(admin contributor)
|
67
67
|
# validates :password, length: 6..20
|
68
68
|
#
|
69
69
|
# When using shortcut form, ranges and arrays are passed to your
|
@@ -116,7 +116,7 @@ module ActiveModel
|
|
116
116
|
key = "#{key.to_s.camelize}Validator"
|
117
117
|
|
118
118
|
begin
|
119
|
-
validator = key.include?("::"
|
119
|
+
validator = key.include?("::") ? key.constantize : const_get(key)
|
120
120
|
rescue NameError
|
121
121
|
raise ArgumentError, "Unknown validator: '#{key}'"
|
122
122
|
end
|
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:
|
4
|
+
version: 6.0.0.beta1
|
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: 2019-
|
11
|
+
date: 2019-01-18 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:
|
19
|
+
version: 6.0.0.beta1
|
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:
|
26
|
+
version: 6.0.0.beta1
|
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,7 +73,6 @@ 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
|
77
76
|
- lib/active_model/type/immutable_string.rb
|
78
77
|
- lib/active_model/type/integer.rb
|
79
78
|
- lib/active_model/type/registry.rb
|
@@ -101,8 +100,8 @@ homepage: http://rubyonrails.org
|
|
101
100
|
licenses:
|
102
101
|
- MIT
|
103
102
|
metadata:
|
104
|
-
source_code_uri: https://github.com/rails/rails/tree/
|
105
|
-
changelog_uri: https://github.com/rails/rails/blob/
|
103
|
+
source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta1/activemodel
|
104
|
+
changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta1/activemodel/CHANGELOG.md
|
106
105
|
post_install_message:
|
107
106
|
rdoc_options: []
|
108
107
|
require_paths:
|
@@ -111,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
110
|
requirements:
|
112
111
|
- - ">="
|
113
112
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.
|
113
|
+
version: 2.5.0
|
115
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
115
|
requirements:
|
117
116
|
- - ">"
|
@@ -1,19 +0,0 @@
|
|
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
|