lite-validators 1.0.5 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -3
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +86 -78
- data/config/locales/en.yml +4 -0
- data/docs/ALPHA.md +3 -3
- data/docs/ALPHA_NUMERIC.md +3 -3
- data/docs/BASE64.md +1 -1
- data/docs/BOOLEAN.md +8 -1
- data/docs/COMPARE.md +1 -1
- data/docs/COORDINATE.md +2 -2
- data/docs/CREDIT_CARD.md +2 -2
- data/docs/CSV.md +3 -3
- data/docs/CURRENCY.md +1 -1
- data/docs/CUSIP.md +1 -1
- data/docs/EMAIL.md +3 -3
- data/docs/FILE_CONTENT_TYPE.md +3 -3
- data/docs/FILE_EXTENSION.md +2 -2
- data/docs/FILE_SIZE.md +3 -3
- data/docs/HEX.md +1 -1
- data/docs/IMEI.md +1 -1
- data/docs/IP_ADDRESS.md +2 -2
- data/docs/ISBN.md +1 -1
- data/docs/ISIN.md +1 -1
- data/docs/MAC_ADDRESS.md +1 -1
- data/docs/NAME.md +1 -1
- data/docs/PASSWORD.md +2 -2
- data/docs/PHONE_NUMBER.md +1 -1
- data/docs/SEDOL.md +1 -1
- data/docs/SLUG.md +1 -1
- data/docs/SSN.md +1 -1
- data/docs/TIME_ZONE.md +1 -1
- data/docs/TYPE.md +5 -5
- data/docs/URL.md +4 -4
- data/docs/USERNAME.md +2 -2
- data/docs/UUID.md +2 -2
- data/lib/lite/validators/alpha_validator.rb +1 -1
- data/lib/lite/validators/base64_validator.rb +1 -3
- data/lib/lite/validators/base_validator.rb +3 -3
- data/lib/lite/validators/boolean_validator.rb +24 -4
- data/lib/lite/validators/compare_validator.rb +1 -1
- data/lib/lite/validators/coordinate_validator.rb +1 -1
- data/lib/lite/validators/credit_card_validator.rb +2 -2
- data/lib/lite/validators/csv_validator.rb +4 -4
- data/lib/lite/validators/currency_validator.rb +1 -1
- data/lib/lite/validators/cusip_validator.rb +1 -1
- data/lib/lite/validators/ein_validator.rb +1 -1
- data/lib/lite/validators/email_validator.rb +2 -2
- 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 +4 -4
- data/lib/lite/validators/hex_validator.rb +1 -1
- 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 +6 -6
- data/lib/lite/validators/mac_address_validator.rb +5 -5
- data/lib/lite/validators/name_validator.rb +1 -1
- data/lib/lite/validators/password_validator.rb +1 -1
- data/lib/lite/validators/phone_number_validator.rb +1 -1
- data/lib/lite/validators/railtie.rb +1 -1
- data/lib/lite/validators/sedol_validator.rb +2 -2
- data/lib/lite/validators/slug_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 +5 -5
- data/lib/lite/validators/username_validator.rb +1 -1
- data/lib/lite/validators/uuid_validator.rb +1 -1
- data/lib/lite/validators/version.rb +1 -1
- metadata +7 -7
@@ -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
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class FileSizeValidator < BaseValidator
|
4
4
|
|
5
|
-
CHECKS
|
5
|
+
CHECKS = {
|
6
6
|
in: :===,
|
7
7
|
less_than: :<,
|
8
8
|
less_than_or_equal_to: :<=,
|
@@ -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
|
6
|
-
REGEXP
|
7
|
-
# rubocop:enable
|
5
|
+
# rubocop:disable Layout/LineLength
|
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 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 }
|
@@ -27,10 +27,10 @@ class IsinValidator < BaseValidator
|
|
27
27
|
|
28
28
|
longest = longest.map { |int| int * 2 }
|
29
29
|
values = longest.concat(shortest).to_s.scan(/./).map(&:to_i)
|
30
|
-
total = values.
|
30
|
+
total = values.sum
|
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
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
class MacAddressValidator < BaseValidator
|
4
4
|
|
5
|
-
REGEXP
|
6
|
-
/^(
|
7
|
-
/^(
|
8
|
-
/^(
|
9
|
-
|
5
|
+
REGEXP = [
|
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
|
@@ -8,7 +8,7 @@ module Lite
|
|
8
8
|
|
9
9
|
initializer 'lite-validators' do |app|
|
10
10
|
Lite::Validators::Railtie.instance_eval do
|
11
|
-
|
11
|
+
Array(app.config.i18n.available_locales).each do |locale|
|
12
12
|
path = File.expand_path("../../../config/locales/#{locale}.yml", __FILE__)
|
13
13
|
next if !File.file?(path) || I18n.load_path.include?(path)
|
14
14
|
|
@@ -4,7 +4,7 @@ require 'uri'
|
|
4
4
|
|
5
5
|
class UrlValidator < BaseValidator
|
6
6
|
|
7
|
-
SCHEMES
|
7
|
+
SCHEMES = %w[
|
8
8
|
http https
|
9
9
|
].freeze
|
10
10
|
|
@@ -31,14 +31,15 @@ class UrlValidator < BaseValidator
|
|
31
31
|
valid_uri? && valid_domain? && valid_scheme? && valid_root?
|
32
32
|
end
|
33
33
|
|
34
|
-
# rubocop:disable Metrics/AbcSize
|
34
|
+
# rubocop:disable Layout/LineLength, Metrics/AbcSize
|
35
35
|
def valid_domain?
|
36
36
|
return true unless options[:domain]
|
37
37
|
|
38
38
|
value_downcased = value.host.to_s.downcase
|
39
|
-
check =
|
39
|
+
check = Array(options[:domain]).any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
|
40
40
|
record.errors.add(attribute, error_message_for(:domain)) unless check
|
41
41
|
end
|
42
|
+
# rubocop:enable Layout/LineLength, Metrics/AbcSize
|
42
43
|
|
43
44
|
def valid_root?
|
44
45
|
return true unless options[:root_only]
|
@@ -51,10 +52,9 @@ class UrlValidator < BaseValidator
|
|
51
52
|
return true unless options[:scheme]
|
52
53
|
|
53
54
|
value_downcased = value.scheme.to_s.downcase
|
54
|
-
check =
|
55
|
+
check = Array(scheme).any? { |sch| value_downcased == sch.to_s.downcase }
|
55
56
|
record.errors.add(attribute, error_message_for(:scheme)) unless check
|
56
57
|
end
|
57
|
-
# rubocop:enable Metrics/AbcSize
|
58
58
|
|
59
59
|
def valid_uri?
|
60
60
|
value.is_a?(URI::Generic)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
class UuidValidator < BaseValidator
|
4
4
|
|
5
|
-
VERSIONS
|
5
|
+
VERSIONS = {
|
6
6
|
any: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
7
7
|
3 => /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
8
8
|
4 => /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
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.1.2
|
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: 2021-05-07 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.2.17
|
264
|
+
signing_key:
|
265
265
|
specification_version: 4
|
266
266
|
summary: Collection of ActiveModel/ActiveRecord validators
|
267
267
|
test_files: []
|