lite-validators 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ade5bbd1d906e70f20bc1b5e5187604f2fd6775e88ece1e3c46032428853b77c
4
- data.tar.gz: '0284aa1c3c38963f35fa9f3907a702bb5217ebda36902262232b6aa8730d67a0'
3
+ metadata.gz: 32c7948a3f64e0f2f5d648e6b78585100ddf30c3907a85df9072b36bd8237f3b
4
+ data.tar.gz: 7bdf81ee68471f5825d0ec93d96c215990c4b8b65dc60fd749206affc98c54db
5
5
  SHA512:
6
- metadata.gz: f7cc8549f33870a80054ab8b9e2429acda6cc5d4298063b8a0ed42a09ef4dca81e32e364f16fa4dc1db6170770ed0394340e973e6adc41f0a9b2bea422c75054
7
- data.tar.gz: 77cd74e2c98c3258bfcb5caabfd4c06e931c9e6bb722e1f5d7b253c5cb9d14c92abbffce230fed9276474d0ba461da0e3636e40a8a6ccf6518920aa837c8915f
6
+ metadata.gz: bc9194585c2429df1cdfccc1439288d94eb3de065dc40491155c01f159355d5c5331175519d01effe12e1e6d5a6050dcab078eee9254ab9ed1a2d1517567f538
7
+ data.tar.gz: '00058c1e04fa56864e51e2bba074059b1ecef3d54361e5651b15718c06de7dface5505dd39c2135ee7c70e27d44e2d5e52a4c874e9c66a8fded2907981174643'
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.6.0] - 2022-02-17
10
+ ### Changed
11
+ - Added List validator
12
+ - Update to use public_send instead of send
13
+
9
14
  ## [1.5.0] - 2022-02-17
10
15
  ### Changed
11
16
  - Added `include_address` to ip_address validator
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-validators (1.5.0)
4
+ lite-validators (1.6.0)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -43,13 +43,13 @@ GEM
43
43
  crass (~> 1.0.2)
44
44
  nokogiri (>= 1.5.9)
45
45
  method_source (1.0.0)
46
- mini_portile2 (2.7.1)
46
+ mini_portile2 (2.8.0)
47
47
  minitest (5.15.0)
48
- nokogiri (1.13.1)
49
- mini_portile2 (~> 2.7.0)
48
+ nokogiri (1.13.3)
49
+ mini_portile2 (~> 2.8.0)
50
50
  racc (~> 1.4)
51
51
  parallel (1.21.0)
52
- parser (3.1.0.0)
52
+ parser (3.1.1.0)
53
53
  ast (~> 2.4.1)
54
54
  racc (1.6.0)
55
55
  rack (2.2.3)
@@ -101,14 +101,14 @@ 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.2)
105
- parser (>= 3.0.1.1)
104
+ rubocop-ast (1.16.0)
105
+ parser (>= 3.1.1.0)
106
106
  rubocop-performance (1.13.2)
107
107
  rubocop (>= 1.7.0, < 2.0)
108
108
  rubocop-ast (>= 0.4.0)
109
109
  rubocop-rake (0.6.0)
110
110
  rubocop (~> 1.0)
111
- rubocop-rspec (2.8.0)
111
+ rubocop-rspec (2.9.0)
112
112
  rubocop (~> 1.19)
113
113
  ruby-progressbar (1.11.0)
114
114
  ruby_parser (3.18.1)
data/README.md CHANGED
@@ -51,6 +51,7 @@ Or install it yourself as:
51
51
  * [IP address](https://github.com/drexed/lite-validators/blob/master/docs/IP_ADDRESS.md)
52
52
  * [ISBN](https://github.com/drexed/lite-validators/blob/master/docs/ISBN.md)
53
53
  * [ISIN](https://github.com/drexed/lite-validators/blob/master/docs/ISIN.md)
54
+ * [List](https://github.com/drexed/lite-validators/blob/master/docs/LIST.md)
54
55
  * [MAC address](https://github.com/drexed/lite-validators/blob/master/docs/MAC.md)
55
56
  * [Name](https://github.com/drexed/lite-validators/blob/master/docs/NAME.md)
56
57
  * [Password](https://github.com/drexed/lite-validators/blob/master/docs/PASSWORD.md)
data/docs/LIST.md ADDED
@@ -0,0 +1,28 @@
1
+ # List
2
+
3
+ #### Rules
4
+
5
+ ```ruby
6
+ # 1. Check
7
+ ```
8
+
9
+ #### Options
10
+
11
+ Option | Type | Available | Default
12
+ --- | --- | --- | ---
13
+ all | array | |
14
+ any | array | |
15
+ none | array | |
16
+
17
+ #### Usage
18
+
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+
22
+ validates :input0, list: { all: %w[monday tuesday] }
23
+ validates :input1, list: { any: %w[saturday sunday] }
24
+ validates :input2, list: { none: %w[wednesday thursday] }
25
+ validates :input3, list: { any: %w[saturday sunday], none: %w[wednesday thursday] }
26
+
27
+ end
28
+ ```
@@ -34,8 +34,8 @@ class CompareValidator < BaseValidator
34
34
  end
35
35
 
36
36
  def valid_attr?
37
- other = record.send(options[:to])
38
- value.send(CHECKS[check], other)
37
+ other = record.public_send(options[:to])
38
+ value.public_send(CHECKS[check], other)
39
39
  end
40
40
 
41
41
  end
@@ -59,9 +59,9 @@ class FileSizeValidator < BaseValidator
59
59
  return false if size.nil?
60
60
 
61
61
  if option_value.is_a?(Range)
62
- option_value.send(CHECKS[option], size)
62
+ option_value.public_send(CHECKS[option], size)
63
63
  else
64
- size.send(CHECKS[option], option_value)
64
+ size.public_send(CHECKS[option], option_value)
65
65
  end
66
66
  end
67
67
 
@@ -37,7 +37,7 @@ class IpAddressValidator < BaseValidator
37
37
  return true unless addresses
38
38
 
39
39
  check = options[:include_address] ? :any? : :none?
40
- check = Array(addresses).send(check) { |address| value.include?(address.to_s) }
40
+ check = Array(addresses).public_send(check) { |address| value.include?(address.to_s) }
41
41
  return true if check
42
42
 
43
43
  record.errors.add(attribute, error_message_for(:address))
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ListValidator < BaseValidator
4
+
5
+ def validate_each(record, attribute, value)
6
+ assert_valid_all_or_any_or_none!
7
+ assign_attr_readers(record, attribute, value)
8
+ valid?
9
+ end
10
+
11
+ private
12
+
13
+ def assert_valid_all_or_any_or_none!
14
+ return if options.key?(:all) || options.key?(:any) || options.key?(:none)
15
+
16
+ raise ArgumentError, 'Missing ":all", ":any" or ":none" attribute for comparison.'
17
+ end
18
+
19
+ def valid_attr?
20
+ options.slice(:all, :any, :none).each do |option, option_value|
21
+ validate_check(option, option_value)
22
+ end
23
+ end
24
+
25
+ def valid_content_type?(option, option_value)
26
+ Array(value).public_send("#{option}?") { |val| option_value.include?(val) }
27
+ end
28
+
29
+ def validate_check(option, option_value)
30
+ return if valid_content_type?(option, option_value)
31
+
32
+ record.errors.add(attribute, *error_message)
33
+ end
34
+
35
+ end
@@ -44,7 +44,7 @@ class UrlValidator < BaseValidator
44
44
 
45
45
  value_downcased = value.host.to_s.downcase
46
46
  check = options[:include_host] ? :any? : :none?
47
- check = Array(hosts).send(check) { |host| value_downcased.include?(host.to_s.downcase) }
47
+ check = Array(hosts).public_send(check) { |host| value_downcased.include?(host.to_s.downcase) }
48
48
  return true if check
49
49
 
50
50
  record.errors.add(attribute, error_message_for(:host))
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Validators
5
5
 
6
- VERSION = '1.5.0'
6
+ VERSION = '1.6.0'
7
7
 
8
8
  end
9
9
  end
@@ -25,6 +25,7 @@ require 'lite/validators/imei_validator'
25
25
  require 'lite/validators/ip_address_validator'
26
26
  require 'lite/validators/isbn_validator'
27
27
  require 'lite/validators/isin_validator'
28
+ require 'lite/validators/list_validator'
28
29
  require 'lite/validators/mac_address_validator'
29
30
  require 'lite/validators/name_validator'
30
31
  require 'lite/validators/password_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.5.0
4
+ version: 1.6.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-17 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -205,6 +205,7 @@ files:
205
205
  - docs/IP_ADDRESS.md
206
206
  - docs/ISBN.md
207
207
  - docs/ISIN.md
208
+ - docs/LIST.md
208
209
  - docs/MAC_ADDRESS.md
209
210
  - docs/NAME.md
210
211
  - docs/PASSWORD.md
@@ -239,6 +240,7 @@ files:
239
240
  - lib/lite/validators/ip_address_validator.rb
240
241
  - lib/lite/validators/isbn_validator.rb
241
242
  - lib/lite/validators/isin_validator.rb
243
+ - lib/lite/validators/list_validator.rb
242
244
  - lib/lite/validators/mac_address_validator.rb
243
245
  - lib/lite/validators/name_validator.rb
244
246
  - lib/lite/validators/password_validator.rb