lite-validators 1.4.0 → 1.5.0
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 +5 -0
- data/Gemfile.lock +4 -4
- data/docs/IP_ADDRESS.md +4 -0
- data/docs/URL.md +2 -0
- data/lib/lite/validators/ip_address_validator.rb +20 -1
- data/lib/lite/validators/url_validator.rb +12 -4
- data/lib/lite/validators/version.rb +1 -1
- data/lib/locales/en.yml +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ade5bbd1d906e70f20bc1b5e5187604f2fd6775e88ece1e3c46032428853b77c
|
4
|
+
data.tar.gz: '0284aa1c3c38963f35fa9f3907a702bb5217ebda36902262232b6aa8730d67a0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7cc8549f33870a80054ab8b9e2429acda6cc5d4298063b8a0ed42a09ef4dca81e32e364f16fa4dc1db6170770ed0394340e973e6adc41f0a9b2bea422c75054
|
7
|
+
data.tar.gz: 77cd74e2c98c3258bfcb5caabfd4c06e931c9e6bb722e1f5d7b253c5cb9d14c92abbffce230fed9276474d0ba461da0e3636e40a8a6ccf6518920aa837c8915f
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.5.0] - 2022-02-17
|
10
|
+
### Changed
|
11
|
+
- Added `include_address` to ip_address validator
|
12
|
+
- Added `exclude_address` to ip_address validator
|
13
|
+
|
9
14
|
## [1.4.0] - 2022-02-11
|
10
15
|
### Changed
|
11
16
|
- Added `include_host` to url validator
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-validators (1.
|
4
|
+
lite-validators (1.5.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
fasterer (0.9.0)
|
38
38
|
colorize (~> 0.7)
|
39
39
|
ruby_parser (>= 3.14.1)
|
40
|
-
i18n (1.
|
40
|
+
i18n (1.10.0)
|
41
41
|
concurrent-ruby (~> 1.0)
|
42
42
|
loofah (2.14.0)
|
43
43
|
crass (~> 1.0.2)
|
@@ -69,7 +69,7 @@ GEM
|
|
69
69
|
zeitwerk (~> 2.5)
|
70
70
|
rainbow (3.1.1)
|
71
71
|
rake (13.0.6)
|
72
|
-
regexp_parser (2.2.
|
72
|
+
regexp_parser (2.2.1)
|
73
73
|
rexml (3.2.5)
|
74
74
|
rspec (3.11.0)
|
75
75
|
rspec-core (~> 3.11.0)
|
@@ -101,7 +101,7 @@ GEM
|
|
101
101
|
rubocop-ast (>= 1.15.1, < 2.0)
|
102
102
|
ruby-progressbar (~> 1.7)
|
103
103
|
unicode-display_width (>= 1.4.0, < 3.0)
|
104
|
-
rubocop-ast (1.15.
|
104
|
+
rubocop-ast (1.15.2)
|
105
105
|
parser (>= 3.0.1.1)
|
106
106
|
rubocop-performance (1.13.2)
|
107
107
|
rubocop (>= 1.7.0, < 2.0)
|
data/docs/IP_ADDRESS.md
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
Option | Type | Available | Default
|
14
14
|
--- | --- | --- | ---
|
15
15
|
protocol | symbol | any, ipv4, ipv6 | any
|
16
|
+
include_address | array, string, symbol | |
|
17
|
+
exclude_address | array, string, symbol | |
|
16
18
|
|
17
19
|
#### Usage
|
18
20
|
|
@@ -21,6 +23,8 @@ class User < ActiveRecord::Base
|
|
21
23
|
|
22
24
|
validates :input0, ip_address: true
|
23
25
|
validates :input1, ip_address: { protocol: :ipv4 }
|
26
|
+
validates :input2, ip_address: { include_address: ['0.0.0.0', '99.39.240.31'] }
|
27
|
+
validates :input3, ip_address: { exclude_address: ['0.0.0.0', '99.39.240.31'] }
|
24
28
|
|
25
29
|
end
|
26
30
|
```
|
data/docs/URL.md
CHANGED
@@ -13,6 +13,8 @@ Option | Type | Available | Default
|
|
13
13
|
domain | array, string, symbol | |
|
14
14
|
root_only | boolean | true, false | false
|
15
15
|
scheme | array, string, symbol | |
|
16
|
+
include_host | array, string, symbol | |
|
17
|
+
exclude_host | array, string, symbol | |
|
16
18
|
|
17
19
|
#### Usage
|
18
20
|
|
@@ -20,11 +20,30 @@ class IpAddressValidator < BaseValidator
|
|
20
20
|
assert_valid_option!(:protocol, REGEXP.keys.push(:any))
|
21
21
|
end
|
22
22
|
|
23
|
+
def error_message_for(option)
|
24
|
+
options[:message] || I18n.t("errors.messages.ip_address.#{option}")
|
25
|
+
end
|
26
|
+
|
23
27
|
def protocol
|
24
28
|
options[:protocol] || :any
|
25
29
|
end
|
26
30
|
|
27
|
-
def
|
31
|
+
def valid?
|
32
|
+
valid_format? && valid_address?
|
33
|
+
end
|
34
|
+
|
35
|
+
def valid_address?
|
36
|
+
addresses = options[:include_address] || options[:exclude_address]
|
37
|
+
return true unless addresses
|
38
|
+
|
39
|
+
check = options[:include_address] ? :any? : :none?
|
40
|
+
check = Array(addresses).send(check) { |address| value.include?(address.to_s) }
|
41
|
+
return true if check
|
42
|
+
|
43
|
+
record.errors.add(attribute, error_message_for(:address))
|
44
|
+
end
|
45
|
+
|
46
|
+
def valid_format?
|
28
47
|
case protocol
|
29
48
|
when :ipv4 then valid_regexp?(:ipv4)
|
30
49
|
when :ipv6 then valid_regexp?(:ipv6)
|
@@ -33,7 +33,9 @@ class UrlValidator < BaseValidator
|
|
33
33
|
|
34
34
|
value_downcased = value.host.to_s.downcase
|
35
35
|
check = Array(options[:domain]).any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
|
36
|
-
|
36
|
+
return true if check
|
37
|
+
|
38
|
+
record.errors.add(attribute, error_message_for(:domain))
|
37
39
|
end
|
38
40
|
|
39
41
|
def valid_host?
|
@@ -43,14 +45,18 @@ class UrlValidator < BaseValidator
|
|
43
45
|
value_downcased = value.host.to_s.downcase
|
44
46
|
check = options[:include_host] ? :any? : :none?
|
45
47
|
check = Array(hosts).send(check) { |host| value_downcased.include?(host.to_s.downcase) }
|
46
|
-
|
48
|
+
return true if check
|
49
|
+
|
50
|
+
record.errors.add(attribute, error_message_for(:host))
|
47
51
|
end
|
48
52
|
|
49
53
|
def valid_root?
|
50
54
|
return true unless options[:root_only]
|
51
55
|
|
52
56
|
check = ['', '/'].include?(value.path) && value.query.blank? && value.fragment.blank?
|
53
|
-
|
57
|
+
return true if check
|
58
|
+
|
59
|
+
record.errors.add(attribute, error_message_for(:root))
|
54
60
|
end
|
55
61
|
|
56
62
|
def valid_scheme?
|
@@ -59,7 +65,9 @@ class UrlValidator < BaseValidator
|
|
59
65
|
value_downcased = value.scheme.to_s.downcase
|
60
66
|
schemes = options[:scheme] || SCHEMES
|
61
67
|
check = Array(schemes).any? { |scheme| value_downcased == scheme.to_s.downcase }
|
62
|
-
|
68
|
+
return true if check
|
69
|
+
|
70
|
+
record.errors.add(attribute, error_message_for(:scheme))
|
63
71
|
end
|
64
72
|
|
65
73
|
def valid_uri?
|
data/lib/locales/en.yml
CHANGED
@@ -21,6 +21,8 @@ en:
|
|
21
21
|
less_than_or_equal_to: "file size is not less than or equal to %{count}"
|
22
22
|
equal_to: "file size is not equal to %{count} but should"
|
23
23
|
not_equal_to: "file size is equal to %{count} but shouldn't"
|
24
|
+
ip_address:
|
25
|
+
address: "has an invalid address"
|
24
26
|
url:
|
25
27
|
domain: "has an invalid domain"
|
26
28
|
host: "has an invalid host"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|