lite-validators 1.7.1 → 1.8.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 +15 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +62 -60
- data/README.md +2 -15
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/lite/validators/alpha_validator.rb +3 -3
- data/lib/lite/validators/base_validator.rb +0 -2
- data/lib/lite/validators/csv_validator.rb +3 -3
- data/lib/lite/validators/cusip_validator.rb +0 -2
- data/lib/lite/validators/file_extension_validator.rb +1 -1
- data/lib/lite/validators/file_size_validator.rb +2 -2
- data/lib/lite/validators/imei_validator.rb +1 -1
- data/lib/lite/validators/ip_address_validator.rb +1 -1
- data/lib/lite/validators/isbn_validator.rb +1 -1
- data/lib/lite/validators/isin_validator.rb +0 -4
- data/lib/lite/validators/railtie.rb +1 -1
- data/lib/lite/validators/reference_validator.rb +4 -3
- data/lib/lite/validators/time_zone_validator.rb +1 -1
- data/lib/lite/validators/url_validator.rb +2 -4
- data/lib/lite/validators/version.rb +1 -1
- data/lib/lite/validators.rb +38 -38
- data/lite-validators.gemspec +25 -31
- metadata +9 -5
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e89a2c77af2dd9641e9c98f3a9a3641a0825e161ce13ef46ed00666d3d71e9dd
|
4
|
+
data.tar.gz: f61e400f2d1ee17c765054659174dfd065a01353a1f183e944cbfd69c704b0f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7801ec742a17a96a871d03c43fa630bb1fb4223b3e0a6c28a660ba802187dcf335b069146b93583f9feb6250cfcba2a8ae79f819d068866aff0f902b631603c1
|
7
|
+
data.tar.gz: cdd0f30c4f78f042979c43bf2e1550543223c083ca46aa96c6c85711c77aad29783fbcc2e583f75139bcb6e14c773477b0159b2411426ddb99c471cee9377fcf
|
data/.rubocop.yml
CHANGED
@@ -3,12 +3,9 @@ require:
|
|
3
3
|
- rubocop-rake
|
4
4
|
- rubocop-rspec
|
5
5
|
AllCops:
|
6
|
-
TargetRubyVersion: 3.0
|
7
6
|
NewCops: enable
|
8
7
|
DisplayCopNames: true
|
9
8
|
DisplayStyleGuide: true
|
10
|
-
Gemspec/RequireMFA:
|
11
|
-
Enabled: false
|
12
9
|
Gemspec/RequiredRubyVersion:
|
13
10
|
Enabled: false
|
14
11
|
Layout/EmptyLinesAroundAttributeAccessor:
|
@@ -21,7 +18,7 @@ Layout/EmptyLinesAroundClassBody:
|
|
21
18
|
Layout/EmptyLinesAroundModuleBody:
|
22
19
|
EnforcedStyle: empty_lines_except_namespace
|
23
20
|
Layout/LineLength:
|
24
|
-
|
21
|
+
Enabled: false
|
25
22
|
Layout/SpaceAroundMethodCallOperator:
|
26
23
|
Enabled: true
|
27
24
|
Lint/ConstantDefinitionInBlock:
|
@@ -32,6 +29,8 @@ Lint/RaiseException:
|
|
32
29
|
Enabled: true
|
33
30
|
Lint/StructNewOverride:
|
34
31
|
Enabled: true
|
32
|
+
Metrics/AbcSize:
|
33
|
+
Enabled: false
|
35
34
|
Metrics/BlockLength:
|
36
35
|
Exclude:
|
37
36
|
- 'spec/**/**/*'
|
@@ -39,8 +38,16 @@ Metrics/BlockLength:
|
|
39
38
|
Metrics/ClassLength:
|
40
39
|
Exclude:
|
41
40
|
- 'lib/lite/validators/credit_card_validator.rb'
|
41
|
+
Metrics/CyclomaticComplexity:
|
42
|
+
Enabled: false
|
43
|
+
Metrics/MethodLength:
|
44
|
+
Enabled: false
|
45
|
+
Metrics/PerceivedComplexity:
|
46
|
+
Enabled: false
|
42
47
|
RSpec/ExampleLength:
|
43
48
|
Enabled: false
|
49
|
+
RSpec/NoExpectationExample:
|
50
|
+
Enabled: false
|
44
51
|
RSpec/LeakyConstantDeclaration:
|
45
52
|
Enabled: false
|
46
53
|
RSpec/MultipleExpectations:
|
@@ -51,3 +58,7 @@ Style/Documentation:
|
|
51
58
|
Enabled: false
|
52
59
|
Style/ExpandPathArguments:
|
53
60
|
Enabled: false
|
61
|
+
Style/HashSyntax:
|
62
|
+
EnforcedShorthandSyntax: never
|
63
|
+
Style/StringLiterals:
|
64
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.8.0] - 2022-11-20
|
10
|
+
### Changed
|
11
|
+
- Improved docs
|
12
|
+
- Improved internal setup
|
13
|
+
- Improved rubocop setup
|
14
|
+
|
15
|
+
## [1.7.2] - 2022-03-18
|
16
|
+
### Changed
|
17
|
+
- Check associated object is valid to reference validator
|
18
|
+
|
9
19
|
## [1.7.1] - 2022-03-17
|
10
20
|
### Changed
|
11
21
|
- Added polymorphic support to reference validator
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-validators (1.
|
4
|
+
lite-validators (1.8.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (7.0.
|
11
|
-
actionview (= 7.0.
|
12
|
-
activesupport (= 7.0.
|
10
|
+
actionpack (7.0.4)
|
11
|
+
actionview (= 7.0.4)
|
12
|
+
activesupport (= 7.0.4)
|
13
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 (7.0.
|
18
|
-
activesupport (= 7.0.
|
17
|
+
actionview (7.0.4)
|
18
|
+
activesupport (= 7.0.4)
|
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 (7.0.
|
24
|
-
activesupport (= 7.0.
|
25
|
-
activesupport (7.0.
|
23
|
+
activemodel (7.0.4)
|
24
|
+
activesupport (= 7.0.4)
|
25
|
+
activesupport (7.0.4)
|
26
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
minitest (>= 5.1)
|
@@ -30,95 +30,97 @@ GEM
|
|
30
30
|
ast (2.4.2)
|
31
31
|
builder (3.2.4)
|
32
32
|
colorize (0.8.1)
|
33
|
-
concurrent-ruby (1.1.
|
33
|
+
concurrent-ruby (1.1.10)
|
34
34
|
crass (1.0.6)
|
35
35
|
diff-lcs (1.5.0)
|
36
|
-
erubi (1.
|
37
|
-
fasterer (0.
|
36
|
+
erubi (1.11.0)
|
37
|
+
fasterer (0.10.0)
|
38
38
|
colorize (~> 0.7)
|
39
|
-
ruby_parser (>= 3.
|
40
|
-
i18n (1.
|
39
|
+
ruby_parser (>= 3.19.1)
|
40
|
+
i18n (1.12.0)
|
41
41
|
concurrent-ruby (~> 1.0)
|
42
|
-
|
42
|
+
json (2.6.2)
|
43
|
+
loofah (2.19.0)
|
43
44
|
crass (~> 1.0.2)
|
44
45
|
nokogiri (>= 1.5.9)
|
45
46
|
method_source (1.0.0)
|
46
47
|
mini_portile2 (2.8.0)
|
47
|
-
minitest (5.
|
48
|
-
nokogiri (1.13.
|
48
|
+
minitest (5.16.3)
|
49
|
+
nokogiri (1.13.9)
|
49
50
|
mini_portile2 (~> 2.8.0)
|
50
51
|
racc (~> 1.4)
|
51
|
-
parallel (1.
|
52
|
-
parser (3.1.1
|
52
|
+
parallel (1.22.1)
|
53
|
+
parser (3.1.2.1)
|
53
54
|
ast (~> 2.4.1)
|
54
55
|
racc (1.6.0)
|
55
|
-
rack (2.2.
|
56
|
-
rack-test (
|
57
|
-
rack (>= 1.
|
56
|
+
rack (2.2.4)
|
57
|
+
rack-test (2.0.2)
|
58
|
+
rack (>= 1.3)
|
58
59
|
rails-dom-testing (2.0.3)
|
59
60
|
activesupport (>= 4.2.0)
|
60
61
|
nokogiri (>= 1.6)
|
61
|
-
rails-html-sanitizer (1.4.
|
62
|
+
rails-html-sanitizer (1.4.3)
|
62
63
|
loofah (~> 2.3)
|
63
|
-
railties (7.0.
|
64
|
-
actionpack (= 7.0.
|
65
|
-
activesupport (= 7.0.
|
64
|
+
railties (7.0.4)
|
65
|
+
actionpack (= 7.0.4)
|
66
|
+
activesupport (= 7.0.4)
|
66
67
|
method_source
|
67
68
|
rake (>= 12.2)
|
68
69
|
thor (~> 1.0)
|
69
70
|
zeitwerk (~> 2.5)
|
70
71
|
rainbow (3.1.1)
|
71
72
|
rake (13.0.6)
|
72
|
-
regexp_parser (2.
|
73
|
+
regexp_parser (2.6.1)
|
73
74
|
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.
|
75
|
+
rspec (3.12.0)
|
76
|
+
rspec-core (~> 3.12.0)
|
77
|
+
rspec-expectations (~> 3.12.0)
|
78
|
+
rspec-mocks (~> 3.12.0)
|
79
|
+
rspec-core (3.12.0)
|
80
|
+
rspec-support (~> 3.12.0)
|
81
|
+
rspec-expectations (3.12.0)
|
81
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-mocks (3.
|
83
|
+
rspec-support (~> 3.12.0)
|
84
|
+
rspec-mocks (3.12.0)
|
84
85
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
-
rspec-support (~> 3.
|
86
|
-
rspec-rails (
|
87
|
-
actionpack (>=
|
88
|
-
activesupport (>=
|
89
|
-
railties (>=
|
90
|
-
rspec-core (~> 3.
|
91
|
-
rspec-expectations (~> 3.
|
92
|
-
rspec-mocks (~> 3.
|
93
|
-
rspec-support (~> 3.
|
94
|
-
rspec-support (3.
|
95
|
-
rubocop (1.
|
86
|
+
rspec-support (~> 3.12.0)
|
87
|
+
rspec-rails (6.0.1)
|
88
|
+
actionpack (>= 6.1)
|
89
|
+
activesupport (>= 6.1)
|
90
|
+
railties (>= 6.1)
|
91
|
+
rspec-core (~> 3.11)
|
92
|
+
rspec-expectations (~> 3.11)
|
93
|
+
rspec-mocks (~> 3.11)
|
94
|
+
rspec-support (~> 3.11)
|
95
|
+
rspec-support (3.12.0)
|
96
|
+
rubocop (1.39.0)
|
97
|
+
json (~> 2.3)
|
96
98
|
parallel (~> 1.10)
|
97
|
-
parser (>= 3.1.
|
99
|
+
parser (>= 3.1.2.1)
|
98
100
|
rainbow (>= 2.2.2, < 4.0)
|
99
101
|
regexp_parser (>= 1.8, < 3.0)
|
100
|
-
rexml
|
101
|
-
rubocop-ast (>= 1.
|
102
|
+
rexml (>= 3.2.5, < 4.0)
|
103
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
102
104
|
ruby-progressbar (~> 1.7)
|
103
105
|
unicode-display_width (>= 1.4.0, < 3.0)
|
104
|
-
rubocop-ast (1.
|
106
|
+
rubocop-ast (1.23.0)
|
105
107
|
parser (>= 3.1.1.0)
|
106
|
-
rubocop-performance (1.
|
108
|
+
rubocop-performance (1.15.1)
|
107
109
|
rubocop (>= 1.7.0, < 2.0)
|
108
110
|
rubocop-ast (>= 0.4.0)
|
109
111
|
rubocop-rake (0.6.0)
|
110
112
|
rubocop (~> 1.0)
|
111
|
-
rubocop-rspec (2.
|
112
|
-
rubocop (~> 1.
|
113
|
+
rubocop-rspec (2.15.0)
|
114
|
+
rubocop (~> 1.33)
|
113
115
|
ruby-progressbar (1.11.0)
|
114
|
-
ruby_parser (3.
|
116
|
+
ruby_parser (3.19.1)
|
115
117
|
sexp_processor (~> 4.16)
|
116
|
-
sexp_processor (4.16.
|
118
|
+
sexp_processor (4.16.1)
|
117
119
|
thor (1.2.1)
|
118
|
-
tzinfo (2.0.
|
120
|
+
tzinfo (2.0.5)
|
119
121
|
concurrent-ruby (~> 1.0)
|
120
|
-
unicode-display_width (2.
|
121
|
-
zeitwerk (2.
|
122
|
+
unicode-display_width (2.3.0)
|
123
|
+
zeitwerk (2.6.6)
|
122
124
|
|
123
125
|
PLATFORMS
|
124
126
|
ruby
|
@@ -137,4 +139,4 @@ DEPENDENCIES
|
|
137
139
|
rubocop-rspec
|
138
140
|
|
139
141
|
BUNDLED WITH
|
140
|
-
2.
|
142
|
+
2.3.26
|
data/README.md
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
|
6
6
|
Lite::Validators is a collection of validators useful for any Rails application.
|
7
7
|
|
8
|
-
**NOTE:** If you are coming from `ActiveValidation`, please read the [port](#port) section.
|
9
|
-
|
10
8
|
## Installation
|
11
9
|
|
12
10
|
Add this line to your application's Gemfile:
|
@@ -27,7 +25,6 @@ Or install it yourself as:
|
|
27
25
|
|
28
26
|
* [Validators](#validators)
|
29
27
|
* [3rd-party](#3rd-party)
|
30
|
-
* [Port](#port)
|
31
28
|
|
32
29
|
## Validators
|
33
30
|
|
@@ -75,16 +72,6 @@ The following are highly recommended 3rd-party validators to supplement your wor
|
|
75
72
|
* **Group:** Group Validations - https://github.com/adzap/grouped_validations
|
76
73
|
* **Overlap:** Validates Overlap - https://github.com/robinbortlik/validates_overlap
|
77
74
|
|
78
|
-
## Port
|
79
|
-
|
80
|
-
`Lite::Validators` is a near compatible port of [ActiveValidation](https://github.com/drexed/active_validation).
|
81
|
-
|
82
|
-
The names for the following validators has been changed, so you will need to make the
|
83
|
-
appropriate changes: `equality #=> compare`, `phone #=> phone_number`
|
84
|
-
|
85
|
-
The syntax for the following validators has been reworked, so you will need to consult the docs
|
86
|
-
for making the appropriate changes: `csv`, `compare`
|
87
|
-
|
88
75
|
## Development
|
89
76
|
|
90
77
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -93,7 +80,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
93
80
|
|
94
81
|
## Contributing
|
95
82
|
|
96
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/drexed/lite-validators. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
97
84
|
|
98
85
|
## License
|
99
86
|
|
@@ -101,4 +88,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
101
88
|
|
102
89
|
## Code of Conduct
|
103
90
|
|
104
|
-
Everyone interacting in the Lite::Validators project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
91
|
+
Everyone interacting in the Lite::Validators project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drexed/lite-validators/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "bundler/setup"
|
5
|
+
require "lite/validators"
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -11,5 +11,5 @@ require 'lite/validators'
|
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
|
-
require
|
14
|
+
require "irb"
|
15
15
|
IRB.start(__FILE__)
|
@@ -19,7 +19,6 @@ class BaseValidator < ActiveModel::EachValidator
|
|
19
19
|
@value = value
|
20
20
|
end
|
21
21
|
|
22
|
-
# rubocop:disable Layout/LineLength
|
23
22
|
def assert_valid_option!(name, collection, option: nil)
|
24
23
|
option ||= send(name)
|
25
24
|
|
@@ -29,7 +28,6 @@ class BaseValidator < ActiveModel::EachValidator
|
|
29
28
|
raise ArgumentError, "Unknown #{name}: #{option_value.inspect}. Valid options are: #{collection.map(&:inspect).join(', ')}"
|
30
29
|
end
|
31
30
|
end
|
32
|
-
# rubocop:enable Layout/LineLength
|
33
31
|
|
34
32
|
def error_message
|
35
33
|
[options[:message] || :invalid]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "csv" unless defined?(CSV)
|
4
4
|
|
5
5
|
class CsvValidator < FileSizeValidator
|
6
6
|
|
@@ -19,7 +19,7 @@ class CsvValidator < FileSizeValidator
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
# rubocop:disable
|
22
|
+
# rubocop:disable 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 Style/GuardClause
|
31
31
|
|
32
32
|
def csv_dimensions(path)
|
33
33
|
dimension = { columns: 0, rows: 0 }
|
@@ -10,7 +10,6 @@ class CusipValidator < BaseValidator
|
|
10
10
|
valid_regexp? && valid_checksum?
|
11
11
|
end
|
12
12
|
|
13
|
-
# rubocop:disable Metrics/AbcSize
|
14
13
|
def valid_checksum?
|
15
14
|
digits = value.chars.map { |chr| /[A-Z]/.match?(chr) ? (chr.ord - 55) : chr.to_i }
|
16
15
|
|
@@ -22,6 +21,5 @@ class CusipValidator < BaseValidator
|
|
22
21
|
|
23
22
|
((10 - values) % 10) % 10
|
24
23
|
end
|
25
|
-
# rubocop:enable Metrics/AbcSize
|
26
24
|
|
27
25
|
end
|
@@ -26,7 +26,7 @@ class FileExtensionValidator < BaseValidator
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def valid_attr?
|
29
|
-
extension = File.extname(value.original_filename).tr(
|
29
|
+
extension = File.extname(value.original_filename).tr(".", "")
|
30
30
|
return false if extension.empty?
|
31
31
|
|
32
32
|
included = include_or_exclude.any? { |ext| ext.to_s == extension }
|
@@ -20,7 +20,7 @@ class FileSizeValidator < BaseValidator
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
# rubocop:disable
|
23
|
+
# rubocop:disable 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 Style/GuardClause
|
32
32
|
|
33
33
|
def checks
|
34
34
|
options.keys & CHECKS.keys
|
@@ -9,7 +9,7 @@ class IsbnValidator < BaseValidator
|
|
9
9
|
private
|
10
10
|
|
11
11
|
def valid_attr?
|
12
|
-
values = value.to_s.gsub(/-| /,
|
12
|
+
values = value.to_s.gsub(/-| /, "").downcase.chars
|
13
13
|
[10, 13].include?(values.size) && values.all? { |chr| CHARACTERS.include?(chr) }
|
14
14
|
end
|
15
15
|
|
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
class IsinValidator < BaseValidator
|
4
4
|
|
5
|
-
# rubocop:disable Layout/LineLength
|
6
5
|
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
|
-
# rubocop:enable Layout/LineLength
|
8
6
|
|
9
7
|
private
|
10
8
|
|
@@ -12,7 +10,6 @@ class IsinValidator < BaseValidator
|
|
12
10
|
valid_regexp? && valid_checksum?
|
13
11
|
end
|
14
12
|
|
15
|
-
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
16
13
|
def valid_checksum?
|
17
14
|
characters = value.chars
|
18
15
|
digits = characters.map { |chr| /[A-Z]/.match?(chr) ? (chr.ord - 55) : chr.to_i }
|
@@ -31,6 +28,5 @@ class IsinValidator < BaseValidator
|
|
31
28
|
|
32
29
|
(10 - (total % 10)) % 10
|
33
30
|
end
|
34
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
35
31
|
|
36
32
|
end
|
@@ -4,7 +4,7 @@ module Lite
|
|
4
4
|
module Validators
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
|
7
|
-
initializer
|
7
|
+
initializer "lite-validators.configure_locales" do |app|
|
8
8
|
Array(app.config.i18n.available_locales).each do |locale|
|
9
9
|
path = File.expand_path("../../../locales/#{locale}.yml", __FILE__)
|
10
10
|
next unless File.file?(path)
|
@@ -21,10 +21,11 @@ class ReferenceValidator < BaseValidator
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def valid_object?
|
24
|
-
|
25
|
-
|
24
|
+
association_type = options[:association] || attribute.to_s.chomp("_id")
|
25
|
+
association_object = record.send(association_type)
|
26
|
+
return true if association_object.present? && association_object.valid?
|
26
27
|
|
27
|
-
record.errors.add(
|
28
|
+
record.errors.add(association_type, *error_message)
|
28
29
|
end
|
29
30
|
|
30
31
|
def valid_type?
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "uri" unless defined?(URI)
|
4
4
|
|
5
5
|
class UrlValidator < BaseValidator
|
6
6
|
|
@@ -21,7 +21,6 @@ class UrlValidator < BaseValidator
|
|
21
21
|
options[:message] || I18n.t("errors.messages.url.#{option}")
|
22
22
|
end
|
23
23
|
|
24
|
-
# rubocop:disable Layout/LineLength, Metrics/AbcSize
|
25
24
|
def valid_attr?
|
26
25
|
raise URI::InvalidURIError if value.to_s.strip.empty?
|
27
26
|
|
@@ -53,7 +52,7 @@ class UrlValidator < BaseValidator
|
|
53
52
|
def valid_root?
|
54
53
|
return true unless options[:root_only]
|
55
54
|
|
56
|
-
check = [
|
55
|
+
check = ["", "/"].include?(value.path) && value.query.blank? && value.fragment.blank?
|
57
56
|
return true if check
|
58
57
|
|
59
58
|
record.errors.add(attribute, error_message_for(:root))
|
@@ -73,6 +72,5 @@ class UrlValidator < BaseValidator
|
|
73
72
|
def valid_uri?
|
74
73
|
value.is_a?(URI::Generic)
|
75
74
|
end
|
76
|
-
# rubocop:enable Layout/LineLength, Metrics/AbcSize
|
77
75
|
|
78
76
|
end
|
data/lib/lite/validators.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "active_model" unless defined?(ActiveModel)
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
5
|
+
require "lite/validators/railtie" if defined?(Rails::Railtie)
|
6
|
+
require "lite/validators/version"
|
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/list_validator"
|
29
|
+
require "lite/validators/mac_address_validator"
|
30
|
+
require "lite/validators/name_validator"
|
31
|
+
require "lite/validators/password_validator"
|
32
|
+
require "lite/validators/phone_number_validator"
|
33
|
+
require "lite/validators/reference_validator"
|
34
|
+
require "lite/validators/sedol_validator"
|
35
|
+
require "lite/validators/slug_validator"
|
36
|
+
require "lite/validators/ssn_validator"
|
37
|
+
require "lite/validators/time_zone_validator"
|
38
|
+
require "lite/validators/type_validator"
|
39
|
+
require "lite/validators/url_validator"
|
40
|
+
require "lite/validators/username_validator"
|
41
|
+
require "lite/validators/uuid_validator"
|
data/lite-validators.gemspec
CHANGED
@@ -1,52 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "lite/validators/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = "lite-validators"
|
9
9
|
spec.version = Lite::Validators::VERSION
|
10
|
-
spec.authors = [
|
10
|
+
spec.authors = ["Juan Gomez"]
|
11
11
|
spec.email = %w[j.gomez@drexed.com]
|
12
12
|
|
13
|
-
spec.summary =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.summary = "Collection of ActiveModel/ActiveRecord validators"
|
14
|
+
spec.homepage = "http://drexed.github.io/lite-validators"
|
15
|
+
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
'source_code_uri' => 'https://github.com/drexed/lite-validators'
|
25
|
-
)
|
26
|
-
else
|
27
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
-
'public gem pushes.'
|
29
|
-
end
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/drexed/lite-validators/blob/master/CHANGELOG.md"
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/drexed/lite-validators"
|
30
24
|
|
31
25
|
# Specify which files should be added to the gem when it is released.
|
32
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
-
spec.files = Dir.chdir(File.expand_path(
|
27
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
34
28
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
29
|
end
|
36
|
-
spec.bindir =
|
30
|
+
spec.bindir = "exe"
|
37
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
32
|
spec.require_paths = %w[lib]
|
39
33
|
|
40
|
-
spec.add_runtime_dependency
|
34
|
+
spec.add_runtime_dependency "activemodel"
|
41
35
|
|
42
|
-
spec.add_development_dependency
|
43
|
-
spec.add_development_dependency
|
44
|
-
spec.add_development_dependency
|
45
|
-
spec.add_development_dependency
|
46
|
-
spec.add_development_dependency
|
47
|
-
spec.add_development_dependency
|
48
|
-
spec.add_development_dependency
|
49
|
-
spec.add_development_dependency
|
50
|
-
spec.add_development_dependency
|
51
|
-
spec.add_development_dependency
|
36
|
+
spec.add_development_dependency "actionpack"
|
37
|
+
spec.add_development_dependency "bundler"
|
38
|
+
spec.add_development_dependency "fasterer"
|
39
|
+
spec.add_development_dependency "rake"
|
40
|
+
spec.add_development_dependency "rspec"
|
41
|
+
spec.add_development_dependency "rspec-rails"
|
42
|
+
spec.add_development_dependency "rubocop"
|
43
|
+
spec.add_development_dependency "rubocop-performance"
|
44
|
+
spec.add_development_dependency "rubocop-rake"
|
45
|
+
spec.add_development_dependency "rubocop-rspec"
|
52
46
|
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.8.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-
|
11
|
+
date: 2022-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -175,7 +175,6 @@ files:
|
|
175
175
|
- ".gitignore"
|
176
176
|
- ".rspec"
|
177
177
|
- ".rubocop.yml"
|
178
|
-
- ".travis.yml"
|
179
178
|
- CHANGELOG.md
|
180
179
|
- CODE_OF_CONDUCT.md
|
181
180
|
- Gemfile
|
@@ -262,7 +261,12 @@ files:
|
|
262
261
|
homepage: http://drexed.github.io/lite-validators
|
263
262
|
licenses:
|
264
263
|
- MIT
|
265
|
-
metadata:
|
264
|
+
metadata:
|
265
|
+
allowed_push_host: https://rubygems.org
|
266
|
+
changelog_uri: https://github.com/drexed/lite-validators/blob/master/CHANGELOG.md
|
267
|
+
homepage_uri: http://drexed.github.io/lite-validators
|
268
|
+
rubygems_mfa_required: 'true'
|
269
|
+
source_code_uri: https://github.com/drexed/lite-validators
|
266
270
|
post_install_message:
|
267
271
|
rdoc_options: []
|
268
272
|
require_paths:
|
@@ -278,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
282
|
- !ruby/object:Gem::Version
|
279
283
|
version: '0'
|
280
284
|
requirements: []
|
281
|
-
rubygems_version: 3.3.
|
285
|
+
rubygems_version: 3.3.26
|
282
286
|
signing_key:
|
283
287
|
specification_version: 4
|
284
288
|
summary: Collection of ActiveModel/ActiveRecord validators
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
sudo: false
|
2
|
-
language: ruby
|
3
|
-
cache: bundler
|
4
|
-
rvm:
|
5
|
-
- 2.5
|
6
|
-
- 2.6
|
7
|
-
- 2.7
|
8
|
-
- ruby-head
|
9
|
-
matrix:
|
10
|
-
fast_finish: true
|
11
|
-
allow_failures:
|
12
|
-
- rvm: ruby-head
|
13
|
-
before_install:
|
14
|
-
- gem update --system
|
15
|
-
- gem install bundler
|
16
|
-
install:
|
17
|
-
- bundle install --jobs=3 --retry=3
|
18
|
-
script:
|
19
|
-
- bundle exec rspec
|
20
|
-
- bundle exec rubocop
|
21
|
-
- bundle exec fasterer
|
22
|
-
notifications:
|
23
|
-
email: false
|
24
|
-
slack:
|
25
|
-
secure: ymrsJTXpcQPEf9MmDKJHIjVo4eLkpuO/Oudt+4uHjqbOukfL4pMbER5FBFEgIqFKR9dM10cCwd5wJf73187CeWQpvm+2Ih2xtenKI/8z5e6iSNvB4+NZiWeIjRmTErAi2qk74m5nOMQ2nGlaKZLvw9VVD0rAQhhem7ec+Ui+ovPH97pNUlDxOgmKUDTtzeaP/jnN0c6kjksAalabg4xnSUhDmImfrRiPux+bTum142bnTx4ahiFQ7tYEi6A9Z4W5IHCgu+YwpT8Hz6OLPWm0BDOLA5sbjgcz2l0SFmwebcPRknDUeBT9+NTZOrhxRWvmJ/TR69hihhZj5k8WQ9wZKCvfl9U7bRFBQdQpU0BD3+cCTnE+sMRzcBaNOp7oXwHpZzeStcZGq0J2qF8lCvqFp2AgpAAnJ/GyC29rLFpWwwMsigFBgjFJnGrv2ZbiKHHbspXRJnGZY79kySfM5CeoY/q74+Jn12712636n2YmpXDglPqhumm6pJ8NvyoMRphRuIt4B9Ar5P1Q0u4QoEdvaCFB9HXR/nOmt/LRskSpCoK7Z0HZJ14YGu58kVR3guviI3ah6bVAzJ1PZZVIn3xUqTApA6csV3uoVh0ZiI8nF+gWbSsFofphRBhAM584D97toT7L5UctZ+KA/oD0Tknc6qXhOo2OLemjvYNW+Cl1g1k=
|