activemodel 5.2.8 → 6.0.0.beta1
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 +38 -163
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_model/attribute/user_provided_default.rb +1 -2
- data/lib/active_model/attribute.rb +3 -4
- 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/builder.rb +1 -3
- data/lib/active_model/attribute_set/yaml_encoder.rb +1 -2
- data/lib/active_model/attribute_set.rb +2 -10
- 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/boolean.rb +1 -10
- 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/time_value.rb +19 -1
- data/lib/active_model/type/helpers.rb +0 -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/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/validations.rb +0 -2
- data/lib/active_model/validator.rb +1 -1
- data/lib/active_model.rb +1 -1
- metadata +10 -11
- data/lib/active_model/type/helpers/timezone.rb +0 -19
@@ -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
|
data/lib/active_model.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
4
|
+
# Copyright (c) 2004-2019 David Heinemeier Hansson
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
# a copy of this software and associated documentation files (the
|
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:
|
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,14 +110,14 @@ 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
|
+
- - ">"
|
118
117
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
118
|
+
version: 1.3.1
|
120
119
|
requirements: []
|
121
|
-
rubygems_version: 3.1
|
120
|
+
rubygems_version: 3.0.1
|
122
121
|
signing_key:
|
123
122
|
specification_version: 4
|
124
123
|
summary: A toolkit for building modeling frameworks (part of Rails).
|
@@ -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
|