lite-validators 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1e56debf660c1cb16481c4ba7e331c1d5f36f6666484b111fd4f54fd5dfe680
4
- data.tar.gz: 1b2b174b568d7e5f2a830fb98acd79064672477911d9ab2f2ce9128e22b4fbb5
3
+ metadata.gz: ade5bbd1d906e70f20bc1b5e5187604f2fd6775e88ece1e3c46032428853b77c
4
+ data.tar.gz: '0284aa1c3c38963f35fa9f3907a702bb5217ebda36902262232b6aa8730d67a0'
5
5
  SHA512:
6
- metadata.gz: b6bff3d5c92d63169e7fe5a73e88383d3e40a17e1a18ece15fa5efea477acdf577618d4ef4b5e9e3498b7bd50de77a4af53b2d468e368053c5f2180b6f9d6fbe
7
- data.tar.gz: 48b1f4e567f69000dd903420c7e0d3d93d55568c34cd00c3849cbd8678fa528f0d14c366e51c2f4921e2b706970ab2c135a0f805e9047b13669d709710af3f8e
6
+ metadata.gz: f7cc8549f33870a80054ab8b9e2429acda6cc5d4298063b8a0ed42a09ef4dca81e32e364f16fa4dc1db6170770ed0394340e973e6adc41f0a9b2bea422c75054
7
+ data.tar.gz: 77cd74e2c98c3258bfcb5caabfd4c06e931c9e6bb722e1f5d7b253c5cb9d14c92abbffce230fed9276474d0ba461da0e3636e40a8a6ccf6518920aa837c8915f
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.5.0] - 2022-02-17
10
+ ### Changed
11
+ - Added `include_address` to ip_address validator
12
+ - Added `exclude_address` to ip_address validator
13
+
9
14
  ## [1.4.0] - 2022-02-11
10
15
  ### Changed
11
16
  - Added `include_host` to url validator
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-validators (1.4.0)
4
+ lite-validators (1.5.0)
5
5
  activemodel
6
6
 
7
7
  GEM
@@ -37,7 +37,7 @@ GEM
37
37
  fasterer (0.9.0)
38
38
  colorize (~> 0.7)
39
39
  ruby_parser (>= 3.14.1)
40
- i18n (1.9.1)
40
+ i18n (1.10.0)
41
41
  concurrent-ruby (~> 1.0)
42
42
  loofah (2.14.0)
43
43
  crass (~> 1.0.2)
@@ -69,7 +69,7 @@ GEM
69
69
  zeitwerk (~> 2.5)
70
70
  rainbow (3.1.1)
71
71
  rake (13.0.6)
72
- regexp_parser (2.2.0)
72
+ regexp_parser (2.2.1)
73
73
  rexml (3.2.5)
74
74
  rspec (3.11.0)
75
75
  rspec-core (~> 3.11.0)
@@ -101,7 +101,7 @@ 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.1)
104
+ rubocop-ast (1.15.2)
105
105
  parser (>= 3.0.1.1)
106
106
  rubocop-performance (1.13.2)
107
107
  rubocop (>= 1.7.0, < 2.0)
data/docs/IP_ADDRESS.md CHANGED
@@ -13,6 +13,8 @@
13
13
  Option | Type | Available | Default
14
14
  --- | --- | --- | ---
15
15
  protocol | symbol | any, ipv4, ipv6 | any
16
+ include_address | array, string, symbol | |
17
+ exclude_address | array, string, symbol | |
16
18
 
17
19
  #### Usage
18
20
 
@@ -21,6 +23,8 @@ class User < ActiveRecord::Base
21
23
 
22
24
  validates :input0, ip_address: true
23
25
  validates :input1, ip_address: { protocol: :ipv4 }
26
+ validates :input2, ip_address: { include_address: ['0.0.0.0', '99.39.240.31'] }
27
+ validates :input3, ip_address: { exclude_address: ['0.0.0.0', '99.39.240.31'] }
24
28
 
25
29
  end
26
30
  ```
data/docs/URL.md CHANGED
@@ -13,6 +13,8 @@ Option | Type | Available | Default
13
13
  domain | array, string, symbol | |
14
14
  root_only | boolean | true, false | false
15
15
  scheme | array, string, symbol | |
16
+ include_host | array, string, symbol | |
17
+ exclude_host | array, string, symbol | |
16
18
 
17
19
  #### Usage
18
20
 
@@ -20,11 +20,30 @@ class IpAddressValidator < BaseValidator
20
20
  assert_valid_option!(:protocol, REGEXP.keys.push(:any))
21
21
  end
22
22
 
23
+ def error_message_for(option)
24
+ options[:message] || I18n.t("errors.messages.ip_address.#{option}")
25
+ end
26
+
23
27
  def protocol
24
28
  options[:protocol] || :any
25
29
  end
26
30
 
27
- def valid_attr?
31
+ def valid?
32
+ valid_format? && valid_address?
33
+ end
34
+
35
+ def valid_address?
36
+ addresses = options[:include_address] || options[:exclude_address]
37
+ return true unless addresses
38
+
39
+ check = options[:include_address] ? :any? : :none?
40
+ check = Array(addresses).send(check) { |address| value.include?(address.to_s) }
41
+ return true if check
42
+
43
+ record.errors.add(attribute, error_message_for(:address))
44
+ end
45
+
46
+ def valid_format?
28
47
  case protocol
29
48
  when :ipv4 then valid_regexp?(:ipv4)
30
49
  when :ipv6 then valid_regexp?(:ipv6)
@@ -33,7 +33,9 @@ class UrlValidator < BaseValidator
33
33
 
34
34
  value_downcased = value.host.to_s.downcase
35
35
  check = Array(options[:domain]).any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
36
- record.errors.add(attribute, error_message_for(:domain)) unless check
36
+ return true if check
37
+
38
+ record.errors.add(attribute, error_message_for(:domain))
37
39
  end
38
40
 
39
41
  def valid_host?
@@ -43,14 +45,18 @@ class UrlValidator < BaseValidator
43
45
  value_downcased = value.host.to_s.downcase
44
46
  check = options[:include_host] ? :any? : :none?
45
47
  check = Array(hosts).send(check) { |host| value_downcased.include?(host.to_s.downcase) }
46
- record.errors.add(attribute, error_message_for(:host)) unless check
48
+ return true if check
49
+
50
+ record.errors.add(attribute, error_message_for(:host))
47
51
  end
48
52
 
49
53
  def valid_root?
50
54
  return true unless options[:root_only]
51
55
 
52
56
  check = ['', '/'].include?(value.path) && value.query.blank? && value.fragment.blank?
53
- record.errors.add(attribute, error_message_for(:root)) unless check
57
+ return true if check
58
+
59
+ record.errors.add(attribute, error_message_for(:root))
54
60
  end
55
61
 
56
62
  def valid_scheme?
@@ -59,7 +65,9 @@ class UrlValidator < BaseValidator
59
65
  value_downcased = value.scheme.to_s.downcase
60
66
  schemes = options[:scheme] || SCHEMES
61
67
  check = Array(schemes).any? { |scheme| value_downcased == scheme.to_s.downcase }
62
- record.errors.add(attribute, error_message_for(:scheme)) unless check
68
+ return true if check
69
+
70
+ record.errors.add(attribute, error_message_for(:scheme))
63
71
  end
64
72
 
65
73
  def valid_uri?
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Validators
5
5
 
6
- VERSION = '1.4.0'
6
+ VERSION = '1.5.0'
7
7
 
8
8
  end
9
9
  end
data/lib/locales/en.yml CHANGED
@@ -21,6 +21,8 @@ en:
21
21
  less_than_or_equal_to: "file size is not less than or equal to %{count}"
22
22
  equal_to: "file size is not equal to %{count} but should"
23
23
  not_equal_to: "file size is equal to %{count} but shouldn't"
24
+ ip_address:
25
+ address: "has an invalid address"
24
26
  url:
25
27
  domain: "has an invalid domain"
26
28
  host: "has an invalid host"
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.0
4
+ version: 1.5.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-11 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel