lite-validators 1.2.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +56 -54
- data/docs/URL.md +3 -1
- data/lib/lite/validators/base64_validator.rb +1 -1
- data/lib/lite/validators/csv_validator.rb +1 -1
- data/lib/lite/validators/currency_validator.rb +1 -1
- data/lib/lite/validators/cusip_validator.rb +2 -2
- data/lib/lite/validators/ein_validator.rb +1 -1
- data/lib/lite/validators/email_validator.rb +1 -1
- data/lib/lite/validators/hex_validator.rb +1 -1
- data/lib/lite/validators/imei_validator.rb +1 -1
- data/lib/lite/validators/ip_address_validator.rb +1 -1
- data/lib/lite/validators/isin_validator.rb +1 -1
- data/lib/lite/validators/name_validator.rb +1 -1
- data/lib/lite/validators/phone_number_validator.rb +1 -1
- data/lib/lite/validators/railtie.rb +8 -10
- data/lib/lite/validators/sedol_validator.rb +2 -2
- data/lib/lite/validators/slug_validator.rb +1 -1
- data/lib/lite/validators/ssn_validator.rb +1 -1
- data/lib/lite/validators/time_zone_validator.rb +1 -1
- data/lib/lite/validators/url_validator.rb +17 -10
- data/lib/lite/validators/username_validator.rb +1 -1
- data/lib/lite/validators/version.rb +1 -1
- data/lib/lite/validators.rb +35 -10
- data/{config → lib}/locales/en.yml +1 -0
- data/lite-validators.gemspec +1 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1e56debf660c1cb16481c4ba7e331c1d5f36f6666484b111fd4f54fd5dfe680
|
4
|
+
data.tar.gz: 1b2b174b568d7e5f2a830fb98acd79064672477911d9ab2f2ce9128e22b4fbb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6bff3d5c92d63169e7fe5a73e88383d3e40a17e1a18ece15fa5efea477acdf577618d4ef4b5e9e3498b7bd50de77a4af53b2d468e368053c5f2180b6f9d6fbe
|
7
|
+
data.tar.gz: 48b1f4e567f69000dd903420c7e0d3d93d55568c34cd00c3849cbd8678fa528f0d14c366e51c2f4921e2b706970ab2c135a0f805e9047b13669d709710af3f8e
|
data/.rubocop.yml
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-performance
|
3
|
+
- rubocop-rake
|
3
4
|
- rubocop-rspec
|
4
5
|
AllCops:
|
5
|
-
TargetRubyVersion:
|
6
|
+
TargetRubyVersion: 3.0
|
6
7
|
NewCops: enable
|
7
8
|
DisplayCopNames: true
|
8
9
|
DisplayStyleGuide: true
|
10
|
+
Gemspec/RequireMFA:
|
11
|
+
Enabled: false
|
9
12
|
Gemspec/RequiredRubyVersion:
|
10
13
|
Enabled: false
|
11
14
|
Layout/EmptyLinesAroundAttributeAccessor:
|
@@ -42,6 +45,8 @@ RSpec/LeakyConstantDeclaration:
|
|
42
45
|
Enabled: false
|
43
46
|
RSpec/MultipleExpectations:
|
44
47
|
Enabled: false
|
48
|
+
Style/ArgumentsForwarding:
|
49
|
+
Enabled: false
|
45
50
|
Style/Documentation:
|
46
51
|
Enabled: false
|
47
52
|
Style/ExpandPathArguments:
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.4.0] - 2022-02-11
|
10
|
+
### Changed
|
11
|
+
- Added `include_host` to url validator
|
12
|
+
- Added `exclude_host` to url validator
|
13
|
+
|
14
|
+
## [1.3.2] - 2021-07-22
|
15
|
+
### Changed
|
16
|
+
- Improved setup
|
17
|
+
|
18
|
+
## [1.3.1] - 2021-07-21
|
19
|
+
### Changed
|
20
|
+
- Improved Railtie support
|
21
|
+
|
22
|
+
## [1.3.0] - 2021-07-19
|
23
|
+
### Added
|
24
|
+
- Added Ruby 3.0 support
|
25
|
+
|
9
26
|
## [1.2.0] - 2021-07-13
|
10
27
|
### Updated
|
11
28
|
- Update name validator to accept numeric values and remove double quotes
|
data/Gemfile.lock
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-validators (1.
|
4
|
+
lite-validators (1.4.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (
|
11
|
-
actionview (=
|
12
|
-
activesupport (=
|
13
|
-
rack (~> 2.0, >= 2.0
|
10
|
+
actionpack (7.0.2.2)
|
11
|
+
actionview (= 7.0.2.2)
|
12
|
+
activesupport (= 7.0.2.2)
|
13
|
+
rack (~> 2.0, >= 2.2.0)
|
14
14
|
rack-test (>= 0.6.3)
|
15
15
|
rails-dom-testing (~> 2.0)
|
16
16
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
-
actionview (
|
18
|
-
activesupport (=
|
17
|
+
actionview (7.0.2.2)
|
18
|
+
activesupport (= 7.0.2.2)
|
19
19
|
builder (~> 3.1)
|
20
20
|
erubi (~> 1.4)
|
21
21
|
rails-dom-testing (~> 2.0)
|
22
22
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
-
activemodel (
|
24
|
-
activesupport (=
|
25
|
-
activesupport (
|
23
|
+
activemodel (7.0.2.2)
|
24
|
+
activesupport (= 7.0.2.2)
|
25
|
+
activesupport (7.0.2.2)
|
26
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
minitest (>= 5.1)
|
29
29
|
tzinfo (~> 2.0)
|
30
|
-
zeitwerk (~> 2.3)
|
31
30
|
ast (2.4.2)
|
32
31
|
builder (3.2.4)
|
33
32
|
colorize (0.8.1)
|
34
33
|
concurrent-ruby (1.1.9)
|
35
34
|
crass (1.0.6)
|
36
|
-
diff-lcs (1.
|
35
|
+
diff-lcs (1.5.0)
|
37
36
|
erubi (1.10.0)
|
38
37
|
fasterer (0.9.0)
|
39
38
|
colorize (~> 0.7)
|
40
39
|
ruby_parser (>= 3.14.1)
|
41
|
-
i18n (1.
|
40
|
+
i18n (1.9.1)
|
42
41
|
concurrent-ruby (~> 1.0)
|
43
|
-
loofah (2.
|
42
|
+
loofah (2.14.0)
|
44
43
|
crass (~> 1.0.2)
|
45
44
|
nokogiri (>= 1.5.9)
|
46
45
|
method_source (1.0.0)
|
47
|
-
mini_portile2 (2.
|
48
|
-
minitest (5.
|
49
|
-
nokogiri (1.
|
50
|
-
mini_portile2 (~> 2.
|
46
|
+
mini_portile2 (2.7.1)
|
47
|
+
minitest (5.15.0)
|
48
|
+
nokogiri (1.13.1)
|
49
|
+
mini_portile2 (~> 2.7.0)
|
51
50
|
racc (~> 1.4)
|
52
|
-
parallel (1.
|
53
|
-
parser (3.0.
|
51
|
+
parallel (1.21.0)
|
52
|
+
parser (3.1.0.0)
|
54
53
|
ast (~> 2.4.1)
|
55
|
-
racc (1.
|
54
|
+
racc (1.6.0)
|
56
55
|
rack (2.2.3)
|
57
56
|
rack-test (1.1.0)
|
58
57
|
rack (>= 1.0, < 3)
|
59
58
|
rails-dom-testing (2.0.3)
|
60
59
|
activesupport (>= 4.2.0)
|
61
60
|
nokogiri (>= 1.6)
|
62
|
-
rails-html-sanitizer (1.
|
61
|
+
rails-html-sanitizer (1.4.2)
|
63
62
|
loofah (~> 2.3)
|
64
|
-
railties (
|
65
|
-
actionpack (=
|
66
|
-
activesupport (=
|
63
|
+
railties (7.0.2.2)
|
64
|
+
actionpack (= 7.0.2.2)
|
65
|
+
activesupport (= 7.0.2.2)
|
67
66
|
method_source
|
68
|
-
rake (>=
|
67
|
+
rake (>= 12.2)
|
69
68
|
thor (~> 1.0)
|
70
|
-
|
69
|
+
zeitwerk (~> 2.5)
|
70
|
+
rainbow (3.1.1)
|
71
71
|
rake (13.0.6)
|
72
|
-
regexp_parser (2.
|
72
|
+
regexp_parser (2.2.0)
|
73
73
|
rexml (3.2.5)
|
74
|
-
rspec (3.
|
75
|
-
rspec-core (~> 3.
|
76
|
-
rspec-expectations (~> 3.
|
77
|
-
rspec-mocks (~> 3.
|
78
|
-
rspec-core (3.
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-expectations (3.
|
74
|
+
rspec (3.11.0)
|
75
|
+
rspec-core (~> 3.11.0)
|
76
|
+
rspec-expectations (~> 3.11.0)
|
77
|
+
rspec-mocks (~> 3.11.0)
|
78
|
+
rspec-core (3.11.0)
|
79
|
+
rspec-support (~> 3.11.0)
|
80
|
+
rspec-expectations (3.11.0)
|
81
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-mocks (3.
|
82
|
+
rspec-support (~> 3.11.0)
|
83
|
+
rspec-mocks (3.11.0)
|
84
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
-
rspec-support (~> 3.
|
86
|
-
rspec-rails (5.0
|
85
|
+
rspec-support (~> 3.11.0)
|
86
|
+
rspec-rails (5.1.0)
|
87
87
|
actionpack (>= 5.2)
|
88
88
|
activesupport (>= 5.2)
|
89
89
|
railties (>= 5.2)
|
@@ -91,33 +91,34 @@ GEM
|
|
91
91
|
rspec-expectations (~> 3.10)
|
92
92
|
rspec-mocks (~> 3.10)
|
93
93
|
rspec-support (~> 3.10)
|
94
|
-
rspec-support (3.
|
95
|
-
rubocop (1.
|
94
|
+
rspec-support (3.11.0)
|
95
|
+
rubocop (1.25.1)
|
96
96
|
parallel (~> 1.10)
|
97
|
-
parser (>= 3.
|
97
|
+
parser (>= 3.1.0.0)
|
98
98
|
rainbow (>= 2.2.2, < 4.0)
|
99
99
|
regexp_parser (>= 1.8, < 3.0)
|
100
100
|
rexml
|
101
|
-
rubocop-ast (>= 1.
|
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.
|
104
|
+
rubocop-ast (1.15.1)
|
105
105
|
parser (>= 3.0.1.1)
|
106
|
-
rubocop-performance (1.
|
106
|
+
rubocop-performance (1.13.2)
|
107
107
|
rubocop (>= 1.7.0, < 2.0)
|
108
108
|
rubocop-ast (>= 0.4.0)
|
109
|
-
rubocop-
|
109
|
+
rubocop-rake (0.6.0)
|
110
110
|
rubocop (~> 1.0)
|
111
|
-
|
111
|
+
rubocop-rspec (2.8.0)
|
112
|
+
rubocop (~> 1.19)
|
112
113
|
ruby-progressbar (1.11.0)
|
113
|
-
ruby_parser (3.
|
114
|
-
sexp_processor (~> 4.
|
115
|
-
sexp_processor (4.
|
116
|
-
thor (1.1
|
114
|
+
ruby_parser (3.18.1)
|
115
|
+
sexp_processor (~> 4.16)
|
116
|
+
sexp_processor (4.16.0)
|
117
|
+
thor (1.2.1)
|
117
118
|
tzinfo (2.0.4)
|
118
119
|
concurrent-ruby (~> 1.0)
|
119
|
-
unicode-display_width (2.
|
120
|
-
zeitwerk (2.4
|
120
|
+
unicode-display_width (2.1.0)
|
121
|
+
zeitwerk (2.5.4)
|
121
122
|
|
122
123
|
PLATFORMS
|
123
124
|
ruby
|
@@ -132,7 +133,8 @@ DEPENDENCIES
|
|
132
133
|
rspec-rails
|
133
134
|
rubocop
|
134
135
|
rubocop-performance
|
136
|
+
rubocop-rake
|
135
137
|
rubocop-rspec
|
136
138
|
|
137
139
|
BUNDLED WITH
|
138
|
-
2.2.
|
140
|
+
2.2.24
|
data/docs/URL.md
CHANGED
@@ -22,7 +22,9 @@ class User < ActiveRecord::Base
|
|
22
22
|
validates :input0, url: true
|
23
23
|
validates :input1, url: { domain: [:com, 'org'] }
|
24
24
|
validates :input2, url: { scheme: :https }
|
25
|
-
validates :input3, url: {
|
25
|
+
validates :input3, url: { include_host: ['example', 'test.org'] }
|
26
|
+
validates :input4, url: { exclude_host: ['example', 'test.org'] }
|
27
|
+
validates :input5, url: { root_only: true }
|
26
28
|
|
27
29
|
end
|
28
30
|
```
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class CusipValidator < BaseValidator
|
4
4
|
|
5
|
-
REGEXP = /^[0-9A-Z]{9}
|
5
|
+
REGEXP = /^[0-9A-Z]{9}$/
|
6
6
|
|
7
7
|
private
|
8
8
|
|
@@ -18,7 +18,7 @@ class CusipValidator < BaseValidator
|
|
18
18
|
odd_values = digits.values_at(*digits.each_index.select(&:odd?))
|
19
19
|
|
20
20
|
values = odd_values.map { |int| int * 2 }.zip(even_values).flatten
|
21
|
-
values = values.inject(0) { |sum, int| sum + (int / 10) + int % 10 }
|
21
|
+
values = values.inject(0) { |sum, int| sum + (int / 10) + (int % 10) }
|
22
22
|
|
23
23
|
((10 - values) % 10) % 10
|
24
24
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
class IsinValidator < BaseValidator
|
4
4
|
|
5
5
|
# rubocop:disable Layout/LineLength
|
6
|
-
REGEXP = /^((AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW{2})([A-Z0-9]{9}))(\d{1})
|
6
|
+
REGEXP = /^((AF|AX|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MK|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|RE|RO|RU|RW|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW{2})([A-Z0-9]{9}))(\d{1})$/
|
7
7
|
# rubocop:enable Layout/LineLength
|
8
8
|
|
9
9
|
private
|
@@ -1,20 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rails/railtie'
|
4
|
-
|
5
3
|
module Lite
|
6
4
|
module Validators
|
7
|
-
class Railtie <
|
5
|
+
class Railtie < Rails::Railtie
|
8
6
|
|
9
|
-
initializer 'lite-validators' do |app|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
next if !File.file?(path) || I18n.load_path.include?(path)
|
7
|
+
initializer 'lite-validators.configure_locales' do |app|
|
8
|
+
Array(app.config.i18n.available_locales).each do |locale|
|
9
|
+
path = File.expand_path("../../../locales/#{locale}.yml", __FILE__)
|
10
|
+
next unless File.file?(path)
|
14
11
|
|
15
|
-
|
16
|
-
end
|
12
|
+
I18n.load_path << path
|
17
13
|
end
|
14
|
+
|
15
|
+
I18n.reload!
|
18
16
|
end
|
19
17
|
|
20
18
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class SedolValidator < BaseValidator
|
4
4
|
|
5
|
-
REGEXP = /^([A-Z0-9]{6})(\d{1})
|
5
|
+
REGEXP = /^([A-Z0-9]{6})(\d{1})$/
|
6
6
|
WEIGHTS = [
|
7
7
|
1, 3, 1, 7, 3, 9, 1
|
8
8
|
].freeze
|
@@ -17,7 +17,7 @@ class SedolValidator < BaseValidator
|
|
17
17
|
total = 0
|
18
18
|
digits = value.chars.map { |dgt| /[A-Z]/.match?(dgt) ? (dgt.ord - 55) : dgt.to_i }
|
19
19
|
digits.each_with_index { |dgt, idx| total += (WEIGHTS[idx] * dgt) }
|
20
|
-
(10 - total % 10) % 10
|
20
|
+
(10 - (total % 10)) % 10
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'uri'
|
3
|
+
require 'uri' unless defined?(URI)
|
4
4
|
|
5
5
|
class UrlValidator < BaseValidator
|
6
6
|
|
@@ -11,27 +11,23 @@ class UrlValidator < BaseValidator
|
|
11
11
|
def validate_each(record, attribute, value)
|
12
12
|
assign_attr_readers(record, attribute, URI.parse(value.to_s))
|
13
13
|
valid_attr?
|
14
|
-
rescue URI::InvalidURIError
|
14
|
+
rescue URI::BadURIError, URI::InvalidURIError
|
15
15
|
record.errors.add(attribute, *error_message)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def scheme
|
21
|
-
options[:scheme] || UrlValidator::SCHEMES
|
22
|
-
end
|
23
|
-
|
24
20
|
def error_message_for(option)
|
25
21
|
options[:message] || I18n.t("errors.messages.url.#{option}")
|
26
22
|
end
|
27
23
|
|
24
|
+
# rubocop:disable Layout/LineLength, Metrics/AbcSize
|
28
25
|
def valid_attr?
|
29
26
|
raise URI::InvalidURIError if value.to_s.strip.empty?
|
30
27
|
|
31
|
-
valid_uri? && valid_domain? && valid_scheme? && valid_root?
|
28
|
+
valid_uri? && valid_host? && valid_domain? && valid_scheme? && valid_root?
|
32
29
|
end
|
33
30
|
|
34
|
-
# rubocop:disable Layout/LineLength, Metrics/AbcSize
|
35
31
|
def valid_domain?
|
36
32
|
return true unless options[:domain]
|
37
33
|
|
@@ -39,7 +35,16 @@ class UrlValidator < BaseValidator
|
|
39
35
|
check = Array(options[:domain]).any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
|
40
36
|
record.errors.add(attribute, error_message_for(:domain)) unless check
|
41
37
|
end
|
42
|
-
|
38
|
+
|
39
|
+
def valid_host?
|
40
|
+
hosts = options[:include_host] || options[:exclude_host]
|
41
|
+
return true unless hosts
|
42
|
+
|
43
|
+
value_downcased = value.host.to_s.downcase
|
44
|
+
check = options[:include_host] ? :any? : :none?
|
45
|
+
check = Array(hosts).send(check) { |host| value_downcased.include?(host.to_s.downcase) }
|
46
|
+
record.errors.add(attribute, error_message_for(:host)) unless check
|
47
|
+
end
|
43
48
|
|
44
49
|
def valid_root?
|
45
50
|
return true unless options[:root_only]
|
@@ -52,12 +57,14 @@ class UrlValidator < BaseValidator
|
|
52
57
|
return true unless options[:scheme]
|
53
58
|
|
54
59
|
value_downcased = value.scheme.to_s.downcase
|
55
|
-
|
60
|
+
schemes = options[:scheme] || SCHEMES
|
61
|
+
check = Array(schemes).any? { |scheme| value_downcased == scheme.to_s.downcase }
|
56
62
|
record.errors.add(attribute, error_message_for(:scheme)) unless check
|
57
63
|
end
|
58
64
|
|
59
65
|
def valid_uri?
|
60
66
|
value.is_a?(URI::Generic)
|
61
67
|
end
|
68
|
+
# rubocop:enable Layout/LineLength, Metrics/AbcSize
|
62
69
|
|
63
70
|
end
|
data/lib/lite/validators.rb
CHANGED
@@ -1,14 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'active_model'
|
3
|
+
require 'active_model' unless defined?(ActiveModel)
|
4
4
|
|
5
|
+
require 'lite/validators/railtie' if defined?(Rails::Railtie)
|
5
6
|
require 'lite/validators/version'
|
6
|
-
require 'lite/validators/
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
require 'lite/validators/base_validator'
|
8
|
+
require 'lite/validators/alpha_validator'
|
9
|
+
require 'lite/validators/alpha_numeric_validator'
|
10
|
+
require 'lite/validators/base64_validator'
|
11
|
+
require 'lite/validators/boolean_validator'
|
12
|
+
require 'lite/validators/compare_validator'
|
13
|
+
require 'lite/validators/coordinate_validator'
|
14
|
+
require 'lite/validators/credit_card_validator'
|
15
|
+
require 'lite/validators/currency_validator'
|
16
|
+
require 'lite/validators/cusip_validator'
|
17
|
+
require 'lite/validators/email_validator'
|
18
|
+
require 'lite/validators/ein_validator'
|
19
|
+
require 'lite/validators/file_content_type_validator'
|
20
|
+
require 'lite/validators/file_extension_validator'
|
21
|
+
require 'lite/validators/file_size_validator'
|
22
|
+
require 'lite/validators/csv_validator'
|
23
|
+
require 'lite/validators/hex_validator'
|
24
|
+
require 'lite/validators/imei_validator'
|
25
|
+
require 'lite/validators/ip_address_validator'
|
26
|
+
require 'lite/validators/isbn_validator'
|
27
|
+
require 'lite/validators/isin_validator'
|
28
|
+
require 'lite/validators/mac_address_validator'
|
29
|
+
require 'lite/validators/name_validator'
|
30
|
+
require 'lite/validators/password_validator'
|
31
|
+
require 'lite/validators/phone_number_validator'
|
32
|
+
require 'lite/validators/sedol_validator'
|
33
|
+
require 'lite/validators/slug_validator'
|
34
|
+
require 'lite/validators/ssn_validator'
|
35
|
+
require 'lite/validators/time_zone_validator'
|
36
|
+
require 'lite/validators/type_validator'
|
37
|
+
require 'lite/validators/url_validator'
|
38
|
+
require 'lite/validators/username_validator'
|
39
|
+
require 'lite/validators/uuid_validator'
|
data/lite-validators.gemspec
CHANGED
@@ -47,5 +47,6 @@ Gem::Specification.new do |spec|
|
|
47
47
|
spec.add_development_dependency 'rspec-rails'
|
48
48
|
spec.add_development_dependency 'rubocop'
|
49
49
|
spec.add_development_dependency 'rubocop-performance'
|
50
|
+
spec.add_development_dependency 'rubocop-rake'
|
50
51
|
spec.add_development_dependency 'rubocop-rspec'
|
51
52
|
end
|
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.4.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:
|
11
|
+
date: 2022-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: rubocop-rspec
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -172,7 +186,6 @@ files:
|
|
172
186
|
- _config.yml
|
173
187
|
- bin/console
|
174
188
|
- bin/setup
|
175
|
-
- config/locales/en.yml
|
176
189
|
- docs/ALPHA.md
|
177
190
|
- docs/ALPHA_NUMERIC.md
|
178
191
|
- docs/BASE64.md
|
@@ -240,6 +253,7 @@ files:
|
|
240
253
|
- lib/lite/validators/username_validator.rb
|
241
254
|
- lib/lite/validators/uuid_validator.rb
|
242
255
|
- lib/lite/validators/version.rb
|
256
|
+
- lib/locales/en.yml
|
243
257
|
- lite-validators.gemspec
|
244
258
|
homepage: http://drexed.github.io/lite-validators
|
245
259
|
licenses:
|
@@ -260,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
274
|
- !ruby/object:Gem::Version
|
261
275
|
version: '0'
|
262
276
|
requirements: []
|
263
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.3.4
|
264
278
|
signing_key:
|
265
279
|
specification_version: 4
|
266
280
|
summary: Collection of ActiveModel/ActiveRecord validators
|