lite-validators 1.0.3 → 1.1.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 +16 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +77 -70
- data/README.md +1 -1
- data/config/locales/en.yml +4 -0
- data/docs/BOOLEAN.md +7 -0
- data/docs/USERNAME.md +1 -1
- data/lib/lite/validators/base64_validator.rb +2 -2
- data/lib/lite/validators/base_validator.rb +3 -3
- data/lib/lite/validators/boolean_validator.rb +24 -4
- data/lib/lite/validators/credit_card_validator.rb +1 -1
- data/lib/lite/validators/csv_validator.rb +3 -3
- data/lib/lite/validators/file_content_type_validator.rb +1 -1
- data/lib/lite/validators/file_extension_validator.rb +1 -3
- data/lib/lite/validators/file_size_validator.rb +3 -3
- data/lib/lite/validators/imei_validator.rb +1 -1
- data/lib/lite/validators/isin_validator.rb +4 -4
- data/lib/lite/validators/mac_address_validator.rb +4 -4
- data/lib/lite/validators/phone_number_validator.rb +1 -1
- data/lib/lite/validators/ssn_validator.rb +1 -1
- data/lib/lite/validators/type_validator.rb +1 -1
- data/lib/lite/validators/url_validator.rb +7 -5
- data/lib/lite/validators/username_validator.rb +1 -1
- data/lib/lite/validators/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54bec919570a21f28c087f804b4d60b6a80483a7b95d333f6cae0345f78cba8b
|
4
|
+
data.tar.gz: 7ca9aa17a309d52c62d6a63c83dd9236f6c6c2697548df1c29037a321f589f80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7957705bf86716d717ed2ab8d00d9a620f2813b31273160a1d8e6085e06cfa4fb3885f2b8b4f2773e8c4a3df9daf8a229ad49a221efbff46615ed2cbcd25cdfa
|
7
|
+
data.tar.gz: 0cc83bed5b93b76c69c30c1e7cbbaad8561004dcefee2d29fed07ca90543dcfb1d557885467ce68d2bc4f76adcb1a2e1173cc8a0a6addef293269f307e7006fb
|
data/.rubocop.yml
CHANGED
@@ -2,11 +2,14 @@ require:
|
|
2
2
|
- rubocop-performance
|
3
3
|
- rubocop-rspec
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion: 2.
|
5
|
+
TargetRubyVersion: 2.7
|
6
|
+
NewCops: enable
|
6
7
|
DisplayCopNames: true
|
7
8
|
DisplayStyleGuide: true
|
8
|
-
|
9
|
-
|
9
|
+
Gemspec/RequiredRubyVersion:
|
10
|
+
Enabled: false
|
11
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
12
|
+
Enabled: true
|
10
13
|
Layout/EmptyLinesAroundBlockBody:
|
11
14
|
Exclude:
|
12
15
|
- 'spec/**/**/*'
|
@@ -14,6 +17,14 @@ Layout/EmptyLinesAroundClassBody:
|
|
14
17
|
EnforcedStyle: empty_lines_except_namespace
|
15
18
|
Layout/EmptyLinesAroundModuleBody:
|
16
19
|
EnforcedStyle: empty_lines_except_namespace
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 100
|
22
|
+
Layout/SpaceAroundMethodCallOperator:
|
23
|
+
Enabled: true
|
24
|
+
Lint/RaiseException:
|
25
|
+
Enabled: true
|
26
|
+
Lint/StructNewOverride:
|
27
|
+
Enabled: true
|
17
28
|
Metrics/BlockLength:
|
18
29
|
Exclude:
|
19
30
|
- 'spec/**/**/*'
|
@@ -23,6 +34,8 @@ Metrics/ClassLength:
|
|
23
34
|
- 'lib/lite/validators/credit_card_validator.rb'
|
24
35
|
RSpec/ExampleLength:
|
25
36
|
Enabled: false
|
37
|
+
RSpec/LeakyConstantDeclaration:
|
38
|
+
Enabled: false
|
26
39
|
RSpec/MultipleExpectations:
|
27
40
|
Enabled: false
|
28
41
|
Style/Documentation:
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.1.0] - 2020-09-04
|
10
|
+
### Updated
|
11
|
+
- Updated username regex
|
12
|
+
|
13
|
+
## [1.0.7] - 2020-07-03
|
14
|
+
### Added
|
15
|
+
- Added Ruby 2.7 support
|
16
|
+
|
17
|
+
## [1.0.6] - 2019-09-18
|
18
|
+
### Added
|
19
|
+
- Added true and false only checks to boolean validator
|
20
|
+
|
21
|
+
## [1.0.5] - 2019-08-09
|
22
|
+
### Added
|
23
|
+
- Added length check to Url validator
|
24
|
+
|
25
|
+
## [1.0.4] - 2019-08-09
|
26
|
+
### Added
|
27
|
+
- Added more boolean value checks
|
28
|
+
|
8
29
|
## [1.0.3] - 2019-07-08
|
9
30
|
### Added
|
10
31
|
- Require rails/railtie in railtie
|
data/Gemfile.lock
CHANGED
@@ -1,113 +1,120 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-validators (1.0
|
4
|
+
lite-validators (1.1.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)
|
10
|
+
actionpack (6.0.3.2)
|
11
|
+
actionview (= 6.0.3.2)
|
12
|
+
activesupport (= 6.0.3.2)
|
13
|
+
rack (~> 2.0, >= 2.0.8)
|
14
14
|
rack-test (>= 0.6.3)
|
15
15
|
rails-dom-testing (~> 2.0)
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
17
|
-
actionview (
|
18
|
-
activesupport (=
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.3.2)
|
18
|
+
activesupport (= 6.0.3.2)
|
19
19
|
builder (~> 3.1)
|
20
20
|
erubi (~> 1.4)
|
21
21
|
rails-dom-testing (~> 2.0)
|
22
|
-
rails-html-sanitizer (~> 1.
|
23
|
-
activemodel (
|
24
|
-
activesupport (=
|
25
|
-
activesupport (
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activemodel (6.0.3.2)
|
24
|
+
activesupport (= 6.0.3.2)
|
25
|
+
activesupport (6.0.3.2)
|
26
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
27
|
i18n (>= 0.7, < 2)
|
28
28
|
minitest (~> 5.1)
|
29
29
|
tzinfo (~> 1.1)
|
30
|
-
|
31
|
-
|
30
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
31
|
+
ast (2.4.1)
|
32
|
+
builder (3.2.4)
|
32
33
|
colorize (0.8.1)
|
33
|
-
concurrent-ruby (1.1.
|
34
|
-
crass (1.0.
|
35
|
-
diff-lcs (1.
|
36
|
-
erubi (1.
|
37
|
-
fasterer (0.
|
34
|
+
concurrent-ruby (1.1.7)
|
35
|
+
crass (1.0.6)
|
36
|
+
diff-lcs (1.4.4)
|
37
|
+
erubi (1.9.0)
|
38
|
+
fasterer (0.8.3)
|
38
39
|
colorize (~> 0.7)
|
39
|
-
ruby_parser (>= 3.
|
40
|
-
i18n (1.
|
40
|
+
ruby_parser (>= 3.14.1)
|
41
|
+
i18n (1.8.5)
|
41
42
|
concurrent-ruby (~> 1.0)
|
42
|
-
|
43
|
-
loofah (2.2.3)
|
43
|
+
loofah (2.7.0)
|
44
44
|
crass (~> 1.0.2)
|
45
45
|
nokogiri (>= 1.5.9)
|
46
|
-
method_source (0.
|
46
|
+
method_source (1.0.0)
|
47
47
|
mini_portile2 (2.4.0)
|
48
|
-
minitest (5.
|
49
|
-
nokogiri (1.10.
|
48
|
+
minitest (5.14.2)
|
49
|
+
nokogiri (1.10.10)
|
50
50
|
mini_portile2 (~> 2.4.0)
|
51
|
-
parallel (1.
|
52
|
-
parser (2.
|
53
|
-
ast (~> 2.4.
|
54
|
-
rack (2.
|
51
|
+
parallel (1.19.2)
|
52
|
+
parser (2.7.1.4)
|
53
|
+
ast (~> 2.4.1)
|
54
|
+
rack (2.2.3)
|
55
55
|
rack-test (1.1.0)
|
56
56
|
rack (>= 1.0, < 3)
|
57
57
|
rails-dom-testing (2.0.3)
|
58
58
|
activesupport (>= 4.2.0)
|
59
59
|
nokogiri (>= 1.6)
|
60
|
-
rails-html-sanitizer (1.0
|
61
|
-
loofah (~> 2.
|
62
|
-
railties (
|
63
|
-
actionpack (=
|
64
|
-
activesupport (=
|
60
|
+
rails-html-sanitizer (1.3.0)
|
61
|
+
loofah (~> 2.3)
|
62
|
+
railties (6.0.3.2)
|
63
|
+
actionpack (= 6.0.3.2)
|
64
|
+
activesupport (= 6.0.3.2)
|
65
65
|
method_source
|
66
66
|
rake (>= 0.8.7)
|
67
|
-
thor (>= 0.
|
67
|
+
thor (>= 0.20.3, < 2.0)
|
68
68
|
rainbow (3.0.0)
|
69
|
-
rake (
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
rspec-
|
74
|
-
|
75
|
-
rspec-
|
76
|
-
rspec-
|
69
|
+
rake (13.0.1)
|
70
|
+
regexp_parser (1.7.1)
|
71
|
+
rexml (3.2.4)
|
72
|
+
rspec (3.9.0)
|
73
|
+
rspec-core (~> 3.9.0)
|
74
|
+
rspec-expectations (~> 3.9.0)
|
75
|
+
rspec-mocks (~> 3.9.0)
|
76
|
+
rspec-core (3.9.2)
|
77
|
+
rspec-support (~> 3.9.3)
|
78
|
+
rspec-expectations (3.9.2)
|
77
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.
|
79
|
-
rspec-mocks (3.
|
80
|
+
rspec-support (~> 3.9.0)
|
81
|
+
rspec-mocks (3.9.1)
|
80
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.
|
82
|
-
rspec-rails (
|
83
|
-
actionpack (>=
|
84
|
-
activesupport (>=
|
85
|
-
railties (>=
|
86
|
-
rspec-core (~> 3.
|
87
|
-
rspec-expectations (~> 3.
|
88
|
-
rspec-mocks (~> 3.
|
89
|
-
rspec-support (~> 3.
|
90
|
-
rspec-support (3.
|
91
|
-
rubocop (0.
|
92
|
-
jaro_winkler (~> 1.5.1)
|
83
|
+
rspec-support (~> 3.9.0)
|
84
|
+
rspec-rails (4.0.1)
|
85
|
+
actionpack (>= 4.2)
|
86
|
+
activesupport (>= 4.2)
|
87
|
+
railties (>= 4.2)
|
88
|
+
rspec-core (~> 3.9)
|
89
|
+
rspec-expectations (~> 3.9)
|
90
|
+
rspec-mocks (~> 3.9)
|
91
|
+
rspec-support (~> 3.9)
|
92
|
+
rspec-support (3.9.3)
|
93
|
+
rubocop (0.90.0)
|
93
94
|
parallel (~> 1.10)
|
94
|
-
parser (>= 2.
|
95
|
+
parser (>= 2.7.1.1)
|
95
96
|
rainbow (>= 2.2.2, < 4.0)
|
97
|
+
regexp_parser (>= 1.7)
|
98
|
+
rexml
|
99
|
+
rubocop-ast (>= 0.3.0, < 1.0)
|
96
100
|
ruby-progressbar (~> 1.7)
|
97
|
-
unicode-display_width (>= 1.4.0, <
|
98
|
-
rubocop-
|
99
|
-
|
100
|
-
rubocop-
|
101
|
-
rubocop (>= 0.
|
101
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
102
|
+
rubocop-ast (0.3.0)
|
103
|
+
parser (>= 2.7.1.4)
|
104
|
+
rubocop-performance (1.8.0)
|
105
|
+
rubocop (>= 0.87.0)
|
106
|
+
rubocop-rspec (1.43.2)
|
107
|
+
rubocop (~> 0.87)
|
102
108
|
ruby-progressbar (1.10.1)
|
103
|
-
ruby_parser (3.
|
109
|
+
ruby_parser (3.15.0)
|
104
110
|
sexp_processor (~> 4.9)
|
105
|
-
sexp_processor (4.
|
106
|
-
thor (0.
|
111
|
+
sexp_processor (4.15.1)
|
112
|
+
thor (1.0.1)
|
107
113
|
thread_safe (0.3.6)
|
108
|
-
tzinfo (1.2.
|
114
|
+
tzinfo (1.2.7)
|
109
115
|
thread_safe (~> 0.1)
|
110
|
-
unicode-display_width (1.
|
116
|
+
unicode-display_width (1.7.0)
|
117
|
+
zeitwerk (2.4.0)
|
111
118
|
|
112
119
|
PLATFORMS
|
113
120
|
ruby
|
@@ -125,4 +132,4 @@ DEPENDENCIES
|
|
125
132
|
rubocop-rspec
|
126
133
|
|
127
134
|
BUNDLED WITH
|
128
|
-
2.
|
135
|
+
2.1.4
|
data/README.md
CHANGED
@@ -66,7 +66,7 @@ Or install it yourself as:
|
|
66
66
|
|
67
67
|
## 3rd-party
|
68
68
|
|
69
|
-
The following are highly recommended 3rd
|
69
|
+
The following are highly recommended 3rd-party validators to supplement your workflow:
|
70
70
|
|
71
71
|
* **DateTime:** Validates Timeliness - https://github.com/adzap/validates_timeliness
|
72
72
|
* **Existence:** Validates Existence - https://github.com/perfectline/validates_existence
|
data/config/locales/en.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
en:
|
2
2
|
errors:
|
3
3
|
messages:
|
4
|
+
boolean:
|
5
|
+
all: "must be a true or false value"
|
6
|
+
false_only: "must be a false value"
|
7
|
+
true_only: "must be a true value"
|
4
8
|
csv:
|
5
9
|
in: "csv %{dimension} is not between %{min} and %{max}"
|
6
10
|
greater_than: "csv %{dimension} is not greater than %{count}"
|
data/docs/BOOLEAN.md
CHANGED
@@ -8,12 +8,19 @@
|
|
8
8
|
'false values' => [false, 0, '0', 'f', 'F', 'false', 'FALSE']
|
9
9
|
```
|
10
10
|
|
11
|
+
#### Options
|
12
|
+
|
13
|
+
Option | Type | Available | Default
|
14
|
+
--- | --- | --- | ---
|
15
|
+
check | symbol | all, false_only, true_only | all
|
16
|
+
|
11
17
|
#### Usage
|
12
18
|
|
13
19
|
```ruby
|
14
20
|
class User < ActiveRecord::Base
|
15
21
|
|
16
22
|
validates :input_0, boolean: true
|
23
|
+
validates :input_1, boolean: { check: :true_only }
|
17
24
|
|
18
25
|
end
|
19
26
|
```
|
data/docs/USERNAME.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
class Base64Validator < BaseValidator
|
4
4
|
|
5
|
-
# rubocop:disable
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
6
|
REGEXP ||= /^(?:[A-Za-z0-9+$]{4})*(?:[A-Za-z0-9+$]{2}==|[A-Za-z0-9+$]{3}=|[A-Za-z0-9+$]{4})$/.freeze
|
7
|
-
# rubocop:enable
|
7
|
+
# rubocop:enable Layout/LineLength
|
8
8
|
|
9
9
|
end
|
@@ -19,17 +19,17 @@ class BaseValidator < ActiveModel::EachValidator
|
|
19
19
|
@value = value
|
20
20
|
end
|
21
21
|
|
22
|
-
# rubocop:disable
|
22
|
+
# rubocop:disable Layout/LineLength
|
23
23
|
def assert_valid_option!(name, collection, option: nil)
|
24
24
|
option ||= send(name)
|
25
25
|
|
26
|
-
|
26
|
+
Array(option).each do |option_value|
|
27
27
|
next if collection.include?(option_value)
|
28
28
|
|
29
29
|
raise ArgumentError, "Unknown #{name}: #{option_value.inspect}. Valid options are: #{collection.map(&:inspect).join(', ')}"
|
30
30
|
end
|
31
31
|
end
|
32
|
-
# rubocop:enable
|
32
|
+
# rubocop:enable Layout/LineLength
|
33
33
|
|
34
34
|
def error_message
|
35
35
|
[options[:message] || :invalid]
|
@@ -2,14 +2,34 @@
|
|
2
2
|
|
3
3
|
class BooleanValidator < BaseValidator
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
CHECKS ||= {
|
6
|
+
all: nil,
|
7
|
+
false_only: %w[0 f false n no off],
|
8
|
+
true_only: %w[1 t true y yes on]
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def validate_each(record, attribute, value)
|
12
|
+
assert_valid_check!
|
13
|
+
super
|
14
|
+
end
|
8
15
|
|
9
16
|
private
|
10
17
|
|
18
|
+
def assert_valid_check!
|
19
|
+
assert_valid_option!(:check, CHECKS.keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
def check
|
23
|
+
options[:check] || :all
|
24
|
+
end
|
25
|
+
|
26
|
+
def error_message
|
27
|
+
[options[:message] || I18n.t("errors.messages.boolean.#{check}")]
|
28
|
+
end
|
29
|
+
|
11
30
|
def valid_attr?
|
12
|
-
|
31
|
+
checks = CHECKS[check] || [].concat(CHECKS[:false_only], CHECKS[:true_only])
|
32
|
+
checks.include?(value.to_s.downcase)
|
13
33
|
end
|
14
34
|
|
15
35
|
end
|
@@ -88,7 +88,7 @@ class CreditCardValidator < BaseValidator
|
|
88
88
|
|
89
89
|
def checksum(value)
|
90
90
|
values = digits(value).reverse.map.with_index { |n, i| i.even? ? n * 2 : n }
|
91
|
-
total = values.reverse.inject(0) { |a, b| a + digits(b).
|
91
|
+
total = values.reverse.inject(0) { |a, b| a + digits(b).sum }
|
92
92
|
checksum = 10 - (total % 10)
|
93
93
|
checksum == 10 ? 0 : checksum
|
94
94
|
end
|
@@ -19,7 +19,7 @@ class CsvValidator < FileSizeValidator
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
# rubocop:disable
|
22
|
+
# rubocop:disable Layout/LineLength, Style/GuardClause
|
23
23
|
def assert_valid_dimensions!
|
24
24
|
if dimensions.empty?
|
25
25
|
raise ArgumentError, "Missing atleast one dimension of #{DIMENSIONS.map(&:inspect).join(', ')} attribute for comparison."
|
@@ -27,7 +27,7 @@ class CsvValidator < FileSizeValidator
|
|
27
27
|
assert_valid_option!(:dimensions, DIMENSIONS)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
# rubocop:enable
|
30
|
+
# rubocop:enable Layout/LineLength, Style/GuardClause
|
31
31
|
|
32
32
|
def csv_dimensions(path)
|
33
33
|
dimension = { columns: 0, rows: 0 }
|
@@ -52,7 +52,7 @@ class CsvValidator < FileSizeValidator
|
|
52
52
|
def error_message_for(dimension, check, check_value)
|
53
53
|
options[:message] || I18n.t(
|
54
54
|
"errors.messages.csv.#{check}",
|
55
|
-
error_options(check_value).merge(dimension: dimension)
|
55
|
+
**error_options(check_value).merge(dimension: dimension)
|
56
56
|
)
|
57
57
|
end
|
58
58
|
|
@@ -24,7 +24,7 @@ class FileContentTypeValidator < BaseValidator
|
|
24
24
|
|
25
25
|
# rubocop:disable Style/CaseEquality
|
26
26
|
def valid_content_type?(option, option_value)
|
27
|
-
check =
|
27
|
+
check = Array(option_value).any? { |type| type === value.content_type }
|
28
28
|
option == :exclude ? !check : check
|
29
29
|
end
|
30
30
|
# rubocop:enable Style/CaseEquality
|
@@ -22,10 +22,9 @@ class FileExtensionValidator < BaseValidator
|
|
22
22
|
|
23
23
|
def include_or_exclude
|
24
24
|
values = options[:include] || options[:exclude]
|
25
|
-
|
25
|
+
Array(values)
|
26
26
|
end
|
27
27
|
|
28
|
-
# rubocop:disable Metrics/AbcSize
|
29
28
|
def valid_attr?
|
30
29
|
extension = File.extname(value.original_filename).tr('.', '')
|
31
30
|
return false if extension.empty?
|
@@ -36,6 +35,5 @@ class FileExtensionValidator < BaseValidator
|
|
36
35
|
|
37
36
|
record.errors.add(attribute, *error_message)
|
38
37
|
end
|
39
|
-
# rubocop:enable Metrics/AbcSize
|
40
38
|
|
41
39
|
end
|
@@ -20,7 +20,7 @@ class FileSizeValidator < BaseValidator
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
# rubocop:disable
|
23
|
+
# rubocop:disable Layout/LineLength, Style/GuardClause
|
24
24
|
def assert_valid_checks!
|
25
25
|
if checks.empty?
|
26
26
|
raise ArgumentError, "Missing atleast one check of #{CHECKS.keys.map(&:inspect).join(', ')} attribute for comparison."
|
@@ -28,7 +28,7 @@ class FileSizeValidator < BaseValidator
|
|
28
28
|
assert_valid_option!(:checks, CHECKS.keys)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
# rubocop:enable
|
31
|
+
# rubocop:enable Layout/LineLength, Style/GuardClause
|
32
32
|
|
33
33
|
def checks
|
34
34
|
options.keys & CHECKS.keys
|
@@ -37,7 +37,7 @@ class FileSizeValidator < BaseValidator
|
|
37
37
|
def error_message_for(option, option_value)
|
38
38
|
options[:message] || I18n.t(
|
39
39
|
"errors.messages.file_size.#{option}",
|
40
|
-
error_options(option_value)
|
40
|
+
**error_options(option_value)
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
class IsinValidator < BaseValidator
|
4
4
|
|
5
|
-
# rubocop:disable
|
5
|
+
# rubocop:disable Layout/LineLength
|
6
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})$/.freeze
|
7
|
-
# rubocop:enable
|
7
|
+
# rubocop:enable Layout/LineLength
|
8
8
|
|
9
9
|
private
|
10
10
|
|
@@ -12,7 +12,7 @@ class IsinValidator < BaseValidator
|
|
12
12
|
valid_regexp? && valid_checksum?
|
13
13
|
end
|
14
14
|
|
15
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
15
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
16
16
|
def valid_checksum?
|
17
17
|
characters = value.chars
|
18
18
|
digits = characters.map { |chr| /[A-Z]/.match?(chr) ? (chr.ord - 55) : chr.to_i }
|
@@ -31,6 +31,6 @@ class IsinValidator < BaseValidator
|
|
31
31
|
|
32
32
|
(10 - (total % 10)) % 10
|
33
33
|
end
|
34
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
34
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
35
35
|
|
36
36
|
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
class MacAddressValidator < BaseValidator
|
4
4
|
|
5
5
|
REGEXP ||= [
|
6
|
-
/^(
|
7
|
-
/^(
|
8
|
-
/^(
|
9
|
-
|
6
|
+
/^(\h{2}[-|.:|\s]){5}\h{2}?$/i,
|
7
|
+
/^(\h{4}[-|.:|\s]){2}\h{4}?$/i,
|
8
|
+
/^(\h{6}[-|.:|\s])\h{6}?$/i,
|
9
|
+
/^\h{12}?$/i
|
10
10
|
].freeze
|
11
11
|
|
12
12
|
private
|
@@ -10,7 +10,7 @@ class UrlValidator < BaseValidator
|
|
10
10
|
|
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
14
|
rescue URI::InvalidURIError
|
15
15
|
record.errors.add(attribute, *error_message)
|
16
16
|
end
|
@@ -26,17 +26,20 @@ class UrlValidator < BaseValidator
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def valid_attr?
|
29
|
+
raise URI::InvalidURIError if value.to_s.strip.empty?
|
30
|
+
|
29
31
|
valid_uri? && valid_domain? && valid_scheme? && valid_root?
|
30
32
|
end
|
31
33
|
|
32
|
-
# rubocop:disable Metrics/AbcSize
|
34
|
+
# rubocop:disable Layout/LineLength, Metrics/AbcSize
|
33
35
|
def valid_domain?
|
34
36
|
return true unless options[:domain]
|
35
37
|
|
36
38
|
value_downcased = value.host.to_s.downcase
|
37
|
-
check =
|
39
|
+
check = Array(options[:domain]).any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
|
38
40
|
record.errors.add(attribute, error_message_for(:domain)) unless check
|
39
41
|
end
|
42
|
+
# rubocop:enable Layout/LineLength, Metrics/AbcSize
|
40
43
|
|
41
44
|
def valid_root?
|
42
45
|
return true unless options[:root_only]
|
@@ -49,10 +52,9 @@ class UrlValidator < BaseValidator
|
|
49
52
|
return true unless options[:scheme]
|
50
53
|
|
51
54
|
value_downcased = value.scheme.to_s.downcase
|
52
|
-
check =
|
55
|
+
check = Array(scheme).any? { |sch| value_downcased == sch.to_s.downcase }
|
53
56
|
record.errors.add(attribute, error_message_for(:scheme)) unless check
|
54
57
|
end
|
55
|
-
# rubocop:enable Metrics/AbcSize
|
56
58
|
|
57
59
|
def valid_uri?
|
58
60
|
value.is_a?(URI::Generic)
|
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description:
|
153
|
+
description:
|
154
154
|
email:
|
155
155
|
- j.gomez@drexed.com
|
156
156
|
executables: []
|
@@ -245,7 +245,7 @@ homepage: http://drexed.github.io/lite-validators
|
|
245
245
|
licenses:
|
246
246
|
- MIT
|
247
247
|
metadata: {}
|
248
|
-
post_install_message:
|
248
|
+
post_install_message:
|
249
249
|
rdoc_options: []
|
250
250
|
require_paths:
|
251
251
|
- lib
|
@@ -260,8 +260,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
260
|
- !ruby/object:Gem::Version
|
261
261
|
version: '0'
|
262
262
|
requirements: []
|
263
|
-
rubygems_version: 3.
|
264
|
-
signing_key:
|
263
|
+
rubygems_version: 3.1.4
|
264
|
+
signing_key:
|
265
265
|
specification_version: 4
|
266
266
|
summary: Collection of ActiveModel/ActiveRecord validators
|
267
267
|
test_files: []
|