can_has_validations 1.3.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/can_has_validations/validators/email_validator.rb +1 -1
- data/lib/can_has_validations/validators/grandparent_validator.rb +1 -1
- data/lib/can_has_validations/validators/hostname_validator.rb +6 -4
- data/lib/can_has_validations/validators/ipaddr_validator.rb +15 -19
- data/lib/can_has_validations/validators/ordering_validator.rb +2 -2
- data/lib/can_has_validations/validators/url_validator.rb +1 -1
- data/lib/can_has_validations/validators/write_once_validator.rb +4 -2
- data/lib/can_has_validations/version.rb +1 -1
- metadata +28 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a60d6f36d2de2de081e45e2608c207d3cc81447900b2f0c7ef61727373fb2819
|
4
|
+
data.tar.gz: aed858aa2888e7646b3878dd039052b0196d9a41e64188bcf45f494dc3bb0e6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db744b1438739df7fd6aae9d071ccbae7683c405fab61ff56307045d2312760b8559b950246a8c578aa3e58c6fdff3d0bbe8f7a27c520d95ea92902b9ef2ef52
|
7
|
+
data.tar.gz: 17486807b2bede046e96282943b8dfa76154e4283d20b8ec18958154f75a24508e919786f2b5e2f802315ee4246c41bfa187b24f93769e67d14767496c34c419
|
@@ -13,7 +13,7 @@ module ActiveModel::Validations
|
|
13
13
|
|
14
14
|
def validate_each(record, attribute, value)
|
15
15
|
unless email_valid?(value)
|
16
|
-
record.errors.add(attribute, :invalid_email, options.merge(value: value))
|
16
|
+
record.errors.add(attribute, :invalid_email, **options.merge(value: value))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ module ActiveModel::Validations
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
unless all_match
|
24
|
-
record.errors.add(attribute, :invalid, options.except(:allow_nil, :parent, :scope))
|
24
|
+
record.errors.add(attribute, :invalid, **options.except(:allow_nil, :parent, :scope))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -24,8 +24,8 @@
|
|
24
24
|
# allows 'a.example.com', but not 'example.com'
|
25
25
|
# validates :domain, hostname: {allow_ip: true} # or 4 or 6 for ipv4 or ipv6 only
|
26
26
|
# allows '1.2.3.4' or 'a.example.com'
|
27
|
-
# validates :subdomain, hostname: {skip_tld: true
|
28
|
-
# allows 'subdomain1'
|
27
|
+
# validates :subdomain, hostname: {skip_tld: true}
|
28
|
+
# allows 'subdomain1'; implies segments: 1..100 unless otherwise specified
|
29
29
|
|
30
30
|
require 'resolv'
|
31
31
|
|
@@ -46,7 +46,7 @@ module ActiveModel::Validations
|
|
46
46
|
return if value =~ Resolv::IPv4::Regex || value =~ Resolv::IPv6::Regex
|
47
47
|
end
|
48
48
|
|
49
|
-
segments = options[:segments] || (2..100)
|
49
|
+
segments = options[:segments] || (options[:skip_tld] ? 1..100 : 2..100)
|
50
50
|
segments = segments..segments if segments.is_a?(Integer)
|
51
51
|
if defined?(Addressable::IDNA)
|
52
52
|
value &&= Addressable::IDNA.to_ascii(value)
|
@@ -63,6 +63,8 @@ module ActiveModel::Validations
|
|
63
63
|
is_valid &&= label.length <= 63
|
64
64
|
if !options[:skip_tld] && idx+1==labels.size
|
65
65
|
is_valid &&= label =~ FINAL_LABEL_REGEXP
|
66
|
+
elsif options[:allow_wildcard]==:multi && idx==0
|
67
|
+
is_valid &&= %w(** *).include?(label) || label =~ LABEL_REGEXP
|
66
68
|
elsif options[:allow_wildcard] && idx==0
|
67
69
|
is_valid &&= label=='*' || label =~ LABEL_REGEXP
|
68
70
|
else
|
@@ -71,7 +73,7 @@ module ActiveModel::Validations
|
|
71
73
|
end
|
72
74
|
|
73
75
|
unless is_valid
|
74
|
-
record.errors.add(attribute, :invalid_hostname, options.except(*RESERVED_OPTIONS).merge!(value: value))
|
76
|
+
record.errors.add(attribute, :invalid_hostname, **options.except(*RESERVED_OPTIONS).merge!(value: value))
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
@@ -30,23 +30,30 @@ module ActiveModel::Validations
|
|
30
30
|
IPAddr.new(value) rescue nil
|
31
31
|
end
|
32
32
|
unless ip
|
33
|
-
record.errors.add(attribute, :invalid_ip, options.merge(value: value))
|
33
|
+
record.errors.add(attribute, :invalid_ip, **options.merge(value: value))
|
34
34
|
return
|
35
35
|
end
|
36
36
|
|
37
37
|
if !options[:allow_block] && (ip.ipv4? && ip.prefix!=32 or ip.ipv6? && ip.prefix!=128)
|
38
|
-
record.errors.add(attribute, :single_ip_required, options.merge(value: value))
|
38
|
+
record.errors.add(attribute, :single_ip_required, **options.merge(value: value))
|
39
39
|
end
|
40
|
-
if allowed_ips && allowed_ips.none?{|blk|
|
41
|
-
record.errors.add(attribute, :ip_not_allowed, options.merge(value: value))
|
42
|
-
elsif disallowed_ips && disallowed_ips.any?{|blk|
|
43
|
-
record.errors.add(attribute, :ip_not_allowed, options.merge(value: value))
|
40
|
+
if allowed_ips && allowed_ips.none?{|blk| ip_within_block? ip, blk}
|
41
|
+
record.errors.add(attribute, :ip_not_allowed, **options.merge(value: value))
|
42
|
+
elsif disallowed_ips && disallowed_ips.any?{|blk| ip_within_block? ip, blk}
|
43
|
+
record.errors.add(attribute, :ip_not_allowed, **options.merge(value: value))
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
+
def ip_within_block?(ip, blk)
|
51
|
+
return false unless ip.family == blk.family
|
52
|
+
ip = ip.to_range
|
53
|
+
blk = blk.to_range
|
54
|
+
ip.begin >= blk.begin && ip.end <= blk.end
|
55
|
+
end
|
56
|
+
|
50
57
|
def normalize_within(val, key)
|
51
58
|
if val.nil? || val.respond_to?(:call) || val.is_a?(Symbol)
|
52
59
|
val
|
@@ -72,20 +79,9 @@ module ActiveModel::Validations
|
|
72
79
|
else
|
73
80
|
val
|
74
81
|
end
|
82
|
+
# raise "#{val.inspect} did not resolve to an Array of IPAddr" unless res.is_a?(Array) && res.all?{|r| r.is_a?(IPAddr)}
|
83
|
+
# res
|
75
84
|
end
|
76
85
|
|
77
86
|
end
|
78
87
|
end
|
79
|
-
|
80
|
-
# tests for & fixes broken IPAddr <= 1.2.2
|
81
|
-
if IPAddr.new('192.168.2.0/32').include? '192.168.2.0/24'
|
82
|
-
# warn 'IPAddr <= 1.2.2 is broken; monkey-patching'
|
83
|
-
class IPAddr
|
84
|
-
def include?(other)
|
85
|
-
range = to_range
|
86
|
-
other = coerce_other(other).to_range
|
87
|
-
range.begin <= other.begin && range.end >= other.end
|
88
|
-
end
|
89
|
-
alias === include?
|
90
|
-
end
|
91
|
-
end
|
@@ -18,7 +18,7 @@ module ActiveModel::Validations
|
|
18
18
|
next unless value && greater
|
19
19
|
unless value < greater
|
20
20
|
attr2 = attr_name.respond_to?(:call) ? 'it is' : record.class.human_attribute_name(attr_name)
|
21
|
-
record.errors.add(attribute, :before, options.except(:before).merge!(attribute2: attr2, value: value))
|
21
|
+
record.errors.add(attribute, :before, **options.except(:before).merge!(attribute2: attr2, value: value))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -33,7 +33,7 @@ module ActiveModel::Validations
|
|
33
33
|
next unless value && lesser
|
34
34
|
unless value > lesser
|
35
35
|
attr2 = attr_name.respond_to?(:call) ? 'it is' : record.class.human_attribute_name(attr_name)
|
36
|
-
record.errors.add(attribute, :after, options.except(:after).merge!(attribute2: attr2, value: value))
|
36
|
+
record.errors.add(attribute, :after, **options.except(:after).merge!(attribute2: attr2, value: value))
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -22,7 +22,7 @@ module ActiveModel::Validations
|
|
22
22
|
u2 = u = URI.parse(value) rescue nil
|
23
23
|
end
|
24
24
|
if !u || !u2 || u.relative? || allowed_schemes.exclude?(u.scheme)
|
25
|
-
record.errors.add(attribute, :invalid_url, options.merge(value: value, scheme: allowed_schemes))
|
25
|
+
record.errors.add(attribute, :invalid_url, **options.merge(value: value, scheme: allowed_schemes))
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -18,7 +18,9 @@ module ActiveModel::Validations
|
|
18
18
|
|
19
19
|
def validate_each(record, attribute, _)
|
20
20
|
return unless record.persisted?
|
21
|
-
if !record.respond_to?("#{attribute}_changed?")
|
21
|
+
if ( !record.respond_to?("#{attribute}_changed?") ||
|
22
|
+
!record.respond_to?("#{attribute}_was")
|
23
|
+
) && record.respond_to?("#{attribute}_id_changed?")
|
22
24
|
attr2 = "#{attribute}_id"
|
23
25
|
else
|
24
26
|
attr2 = attribute
|
@@ -26,7 +28,7 @@ module ActiveModel::Validations
|
|
26
28
|
if record.send("#{attr2}_changed?")
|
27
29
|
if options[:immutable_nil] || !record.send("#{attr2}_was").nil?
|
28
30
|
value = record.read_attribute_for_validation(attribute)
|
29
|
-
record.errors.add(attribute, :unchangeable, options.except(:immutable_nil).merge!(value: value))
|
31
|
+
record.errors.add(attribute, :unchangeable, **options.except(:immutable_nil).merge!(value: value))
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_has_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '5.
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sqlite3
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,8 +44,8 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
-
description: 'Assorted Rails 5.x-
|
48
|
-
Hostname, IP address, Ordering, URL, Write Once'
|
47
|
+
description: 'Assorted Rails 5.x-7.x validators: Array, Email, Existence, Grandparent,
|
48
|
+
Hash keys, Hash values, Hostname, IP address, Ordering, URL, Write Once'
|
49
49
|
email:
|
50
50
|
- tm@iprog.com
|
51
51
|
executables: []
|
@@ -121,39 +121,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.2.22
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
|
-
summary: Assorted Rails 5.x-
|
127
|
+
summary: Assorted Rails 5.x-7.x validators
|
128
128
|
test_files:
|
129
|
-
- test/
|
130
|
-
- test/dummy/
|
129
|
+
- test/can_has_validations_test.rb
|
130
|
+
- test/dummy/README.rdoc
|
131
|
+
- test/dummy/Rakefile
|
131
132
|
- test/dummy/app/assets/javascripts/application.js
|
132
133
|
- test/dummy/app/assets/stylesheets/application.css
|
134
|
+
- test/dummy/app/controllers/application_controller.rb
|
133
135
|
- test/dummy/app/helpers/application_helper.rb
|
134
|
-
- test/dummy/
|
135
|
-
- test/dummy/config/locales/en.yml
|
136
|
-
- test/dummy/config/environments/production.rb
|
137
|
-
- test/dummy/config/environments/development.rb
|
138
|
-
- test/dummy/config/environments/test.rb
|
139
|
-
- test/dummy/config/environment.rb
|
136
|
+
- test/dummy/app/views/layouts/application.html.erb
|
140
137
|
- test/dummy/config/application.rb
|
141
|
-
- test/dummy/config/database.yml
|
142
138
|
- test/dummy/config/boot.rb
|
139
|
+
- test/dummy/config/database.yml
|
140
|
+
- test/dummy/config/environment.rb
|
141
|
+
- test/dummy/config/environments/development.rb
|
142
|
+
- test/dummy/config/environments/production.rb
|
143
|
+
- test/dummy/config/environments/test.rb
|
143
144
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
145
|
+
- test/dummy/config/initializers/inflections.rb
|
144
146
|
- test/dummy/config/initializers/mime_types.rb
|
147
|
+
- test/dummy/config/initializers/secret_token.rb
|
145
148
|
- test/dummy/config/initializers/session_store.rb
|
146
149
|
- test/dummy/config/initializers/wrap_parameters.rb
|
147
|
-
- test/dummy/config/
|
148
|
-
- test/dummy/config/
|
150
|
+
- test/dummy/config/locales/en.yml
|
151
|
+
- test/dummy/config/routes.rb
|
149
152
|
- test/dummy/config.ru
|
150
|
-
- test/dummy/
|
151
|
-
- test/dummy/
|
152
|
-
- test/dummy/public/favicon.ico
|
153
|
+
- test/dummy/log/test.log
|
154
|
+
- test/dummy/public/404.html
|
153
155
|
- test/dummy/public/422.html
|
154
156
|
- test/dummy/public/500.html
|
155
|
-
- test/dummy/public/
|
156
|
-
- test/dummy/
|
157
|
-
- test/dummy/README.rdoc
|
158
|
-
- test/can_has_validations_test.rb
|
157
|
+
- test/dummy/public/favicon.ico
|
158
|
+
- test/dummy/script/rails
|
159
159
|
- test/test_helper.rb
|