lite-validators 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/docs/REFERENCE.md +25 -0
- data/lib/lite/validators/reference_validator.rb +28 -0
- data/lib/lite/validators/version.rb +1 -1
- data/lib/lite/validators.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c30c0e86b00cc4525b0878c22cf5d5dfae82ffa4b3301726197d51c46efaba7e
|
4
|
+
data.tar.gz: 926913306e4b90b172db620412c5018090888b0bc8f76f3c3097f583c941f705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c53420f1612dd642452e7b9e1720e89cab49de4dd75d61e4c040eecc8474066908449be8d9740f39386ae52f3652428e4a6ab19c2be01b97789ba86282b242d4
|
7
|
+
data.tar.gz: 6ccb77637a747d155539cd2b7fc06a868fb4e816ccf501099b891968f132bb0f6aa0d8d967aaefcf1fe33e35303464724ad0b9973cea2bd96273f50c0805d66b
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.7.0] - 2022-03-17
|
10
|
+
### Added
|
11
|
+
- Added Reference validator
|
12
|
+
|
9
13
|
## [1.6.0] - 2022-02-17
|
10
|
-
###
|
14
|
+
### Added
|
11
15
|
- Added List validator
|
16
|
+
### Changed
|
12
17
|
- Update to use public_send instead of send
|
13
18
|
|
14
19
|
## [1.5.0] - 2022-02-17
|
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.7.0)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionpack (7.0.2.
|
11
|
-
actionview (= 7.0.2.
|
12
|
-
activesupport (= 7.0.2.
|
10
|
+
actionpack (7.0.2.3)
|
11
|
+
actionview (= 7.0.2.3)
|
12
|
+
activesupport (= 7.0.2.3)
|
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.2.
|
18
|
-
activesupport (= 7.0.2.
|
17
|
+
actionview (7.0.2.3)
|
18
|
+
activesupport (= 7.0.2.3)
|
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.2.
|
24
|
-
activesupport (= 7.0.2.
|
25
|
-
activesupport (7.0.2.
|
23
|
+
activemodel (7.0.2.3)
|
24
|
+
activesupport (= 7.0.2.3)
|
25
|
+
activesupport (7.0.2.3)
|
26
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
minitest (>= 5.1)
|
@@ -39,7 +39,7 @@ GEM
|
|
39
39
|
ruby_parser (>= 3.14.1)
|
40
40
|
i18n (1.10.0)
|
41
41
|
concurrent-ruby (~> 1.0)
|
42
|
-
loofah (2.
|
42
|
+
loofah (2.15.0)
|
43
43
|
crass (~> 1.0.2)
|
44
44
|
nokogiri (>= 1.5.9)
|
45
45
|
method_source (1.0.0)
|
@@ -60,9 +60,9 @@ GEM
|
|
60
60
|
nokogiri (>= 1.6)
|
61
61
|
rails-html-sanitizer (1.4.2)
|
62
62
|
loofah (~> 2.3)
|
63
|
-
railties (7.0.2.
|
64
|
-
actionpack (= 7.0.2.
|
65
|
-
activesupport (= 7.0.2.
|
63
|
+
railties (7.0.2.3)
|
64
|
+
actionpack (= 7.0.2.3)
|
65
|
+
activesupport (= 7.0.2.3)
|
66
66
|
method_source
|
67
67
|
rake (>= 12.2)
|
68
68
|
thor (~> 1.0)
|
@@ -83,7 +83,7 @@ GEM
|
|
83
83
|
rspec-mocks (3.11.0)
|
84
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
85
|
rspec-support (~> 3.11.0)
|
86
|
-
rspec-rails (5.1.
|
86
|
+
rspec-rails (5.1.1)
|
87
87
|
actionpack (>= 5.2)
|
88
88
|
activesupport (>= 5.2)
|
89
89
|
railties (>= 5.2)
|
@@ -92,18 +92,18 @@ GEM
|
|
92
92
|
rspec-mocks (~> 3.10)
|
93
93
|
rspec-support (~> 3.10)
|
94
94
|
rspec-support (3.11.0)
|
95
|
-
rubocop (1.
|
95
|
+
rubocop (1.26.0)
|
96
96
|
parallel (~> 1.10)
|
97
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.16.0, < 2.0)
|
102
102
|
ruby-progressbar (~> 1.7)
|
103
103
|
unicode-display_width (>= 1.4.0, < 3.0)
|
104
104
|
rubocop-ast (1.16.0)
|
105
105
|
parser (>= 3.1.1.0)
|
106
|
-
rubocop-performance (1.13.
|
106
|
+
rubocop-performance (1.13.3)
|
107
107
|
rubocop (>= 1.7.0, < 2.0)
|
108
108
|
rubocop-ast (>= 0.4.0)
|
109
109
|
rubocop-rake (0.6.0)
|
data/README.md
CHANGED
@@ -56,6 +56,7 @@ Or install it yourself as:
|
|
56
56
|
* [Name](https://github.com/drexed/lite-validators/blob/master/docs/NAME.md)
|
57
57
|
* [Password](https://github.com/drexed/lite-validators/blob/master/docs/PASSWORD.md)
|
58
58
|
* [Phone number](https://github.com/drexed/lite-validators/blob/master/docs/PHONE_NUMBER.md)
|
59
|
+
* [Reference](https://github.com/drexed/lite-validators/blob/master/docs/REFERENCE.md)
|
59
60
|
* [SEDOL](https://github.com/drexed/lite-validators/blob/master/docs/SEDOL.md)
|
60
61
|
* [Slug](https://github.com/drexed/lite-validators/blob/master/docs/SLUG.md)
|
61
62
|
* [SSN](https://github.com/drexed/lite-validators/blob/master/docs/SSN.md)
|
data/docs/REFERENCE.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Reference
|
2
|
+
|
3
|
+
#### Rules
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# 1. Pattern
|
7
|
+
/\A[+-]?\d+\z/
|
8
|
+
```
|
9
|
+
|
10
|
+
#### Options
|
11
|
+
|
12
|
+
Option | Type | Available | Default
|
13
|
+
--- | --- | --- | ---
|
14
|
+
association | symbol | object method | attribute without `_id`
|
15
|
+
|
16
|
+
#### Usage
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class User < ActiveRecord::Base
|
20
|
+
|
21
|
+
validates :input_id, reference: true
|
22
|
+
validates :output_id, reference: { association: :input }
|
23
|
+
|
24
|
+
end
|
25
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ReferenceValidator < BaseValidator
|
4
|
+
|
5
|
+
REGEXP = /\A[+-]?\d+\z/
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
valid_id? || valid_object?
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid_id?
|
14
|
+
if value.blank?
|
15
|
+
false
|
16
|
+
elsif !valid_regexp?
|
17
|
+
record.errors.add(attribute, *error_message)
|
18
|
+
else
|
19
|
+
!value.to_i.negative?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid_object?
|
24
|
+
association_object = options[:association] || attribute.to_s.chomp('_id')
|
25
|
+
record.send(association_object).present?
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/lite/validators.rb
CHANGED
@@ -30,6 +30,7 @@ require 'lite/validators/mac_address_validator'
|
|
30
30
|
require 'lite/validators/name_validator'
|
31
31
|
require 'lite/validators/password_validator'
|
32
32
|
require 'lite/validators/phone_number_validator'
|
33
|
+
require 'lite/validators/reference_validator'
|
33
34
|
require 'lite/validators/sedol_validator'
|
34
35
|
require 'lite/validators/slug_validator'
|
35
36
|
require 'lite/validators/ssn_validator'
|
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.7.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-03-
|
11
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- docs/NAME.md
|
211
211
|
- docs/PASSWORD.md
|
212
212
|
- docs/PHONE_NUMBER.md
|
213
|
+
- docs/REFERENCE.md
|
213
214
|
- docs/SEDOL.md
|
214
215
|
- docs/SLUG.md
|
215
216
|
- docs/SSN.md
|
@@ -246,6 +247,7 @@ files:
|
|
246
247
|
- lib/lite/validators/password_validator.rb
|
247
248
|
- lib/lite/validators/phone_number_validator.rb
|
248
249
|
- lib/lite/validators/railtie.rb
|
250
|
+
- lib/lite/validators/reference_validator.rb
|
249
251
|
- lib/lite/validators/sedol_validator.rb
|
250
252
|
- lib/lite/validators/slug_validator.rb
|
251
253
|
- lib/lite/validators/ssn_validator.rb
|