can_has_validations 1.3.1 → 1.3.2
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/lib/can_has_validations/validators/ipaddr_validator.rb +11 -15
- data/lib/can_has_validations/version.rb +1 -1
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e81561f7a3d00cd1e760d29b9e529d51eb841e5b09bc91832fb4b4f0dbc71a1
|
4
|
+
data.tar.gz: 4ddd43af1f9f5397185d491ee7f38191f2c00bcc15a0a2c78b339ad88ddbd725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30e3b36920d45b0d8e9b0d12ef404b03eb838aa12b905e462b38b407c44c23a91db19f21c7918c396982f69f4afd1afed5585ae795d6d32d4ab93d12aede28a5
|
7
|
+
data.tar.gz: 668d9ad8cccfa46754a67d7648f046f36a708c67ff98dcfde4c9392f071446cbbfb365211de82370833cbc92cb25ba118eea18002bbdec8ff204b4ef87e5354f
|
@@ -37,9 +37,9 @@ module ActiveModel::Validations
|
|
37
37
|
if !options[:allow_block] && (ip.ipv4? && ip.prefix!=32 or ip.ipv6? && ip.prefix!=128)
|
38
38
|
record.errors.add(attribute, :single_ip_required, **options.merge(value: value))
|
39
39
|
end
|
40
|
-
if allowed_ips && allowed_ips.none?{|blk|
|
40
|
+
if allowed_ips && allowed_ips.none?{|blk| ip_within_block? ip, blk}
|
41
41
|
record.errors.add(attribute, :ip_not_allowed, **options.merge(value: value))
|
42
|
-
elsif disallowed_ips && disallowed_ips.any?{|blk|
|
42
|
+
elsif disallowed_ips && disallowed_ips.any?{|blk| ip_within_block? ip, blk}
|
43
43
|
record.errors.add(attribute, :ip_not_allowed, **options.merge(value: value))
|
44
44
|
end
|
45
45
|
end
|
@@ -47,6 +47,13 @@ module ActiveModel::Validations
|
|
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
|
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.3.
|
4
|
+
version: 1.3.2
|
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-05-
|
11
|
+
date: 2021-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -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.15
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Assorted Rails 5.x-6.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
|