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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +18 -3
  3. data/.travis.yml +1 -0
  4. data/CHANGELOG.md +20 -0
  5. data/Gemfile.lock +86 -78
  6. data/config/locales/en.yml +4 -0
  7. data/docs/ALPHA.md +3 -3
  8. data/docs/ALPHA_NUMERIC.md +3 -3
  9. data/docs/BASE64.md +1 -1
  10. data/docs/BOOLEAN.md +8 -1
  11. data/docs/COMPARE.md +1 -1
  12. data/docs/COORDINATE.md +2 -2
  13. data/docs/CREDIT_CARD.md +2 -2
  14. data/docs/CSV.md +3 -3
  15. data/docs/CURRENCY.md +1 -1
  16. data/docs/CUSIP.md +1 -1
  17. data/docs/EMAIL.md +3 -3
  18. data/docs/FILE_CONTENT_TYPE.md +3 -3
  19. data/docs/FILE_EXTENSION.md +2 -2
  20. data/docs/FILE_SIZE.md +3 -3
  21. data/docs/HEX.md +1 -1
  22. data/docs/IMEI.md +1 -1
  23. data/docs/IP_ADDRESS.md +2 -2
  24. data/docs/ISBN.md +1 -1
  25. data/docs/ISIN.md +1 -1
  26. data/docs/MAC_ADDRESS.md +1 -1
  27. data/docs/NAME.md +1 -1
  28. data/docs/PASSWORD.md +2 -2
  29. data/docs/PHONE_NUMBER.md +1 -1
  30. data/docs/SEDOL.md +1 -1
  31. data/docs/SLUG.md +1 -1
  32. data/docs/SSN.md +1 -1
  33. data/docs/TIME_ZONE.md +1 -1
  34. data/docs/TYPE.md +5 -5
  35. data/docs/URL.md +4 -4
  36. data/docs/USERNAME.md +2 -2
  37. data/docs/UUID.md +2 -2
  38. data/lib/lite/validators/alpha_validator.rb +1 -1
  39. data/lib/lite/validators/base64_validator.rb +1 -3
  40. data/lib/lite/validators/base_validator.rb +3 -3
  41. data/lib/lite/validators/boolean_validator.rb +24 -4
  42. data/lib/lite/validators/compare_validator.rb +1 -1
  43. data/lib/lite/validators/coordinate_validator.rb +1 -1
  44. data/lib/lite/validators/credit_card_validator.rb +2 -2
  45. data/lib/lite/validators/csv_validator.rb +4 -4
  46. data/lib/lite/validators/currency_validator.rb +1 -1
  47. data/lib/lite/validators/cusip_validator.rb +1 -1
  48. data/lib/lite/validators/ein_validator.rb +1 -1
  49. data/lib/lite/validators/email_validator.rb +2 -2
  50. data/lib/lite/validators/file_content_type_validator.rb +1 -1
  51. data/lib/lite/validators/file_extension_validator.rb +1 -3
  52. data/lib/lite/validators/file_size_validator.rb +4 -4
  53. data/lib/lite/validators/hex_validator.rb +1 -1
  54. data/lib/lite/validators/imei_validator.rb +1 -1
  55. data/lib/lite/validators/ip_address_validator.rb +1 -1
  56. data/lib/lite/validators/isbn_validator.rb +1 -1
  57. data/lib/lite/validators/isin_validator.rb +6 -6
  58. data/lib/lite/validators/mac_address_validator.rb +5 -5
  59. data/lib/lite/validators/name_validator.rb +1 -1
  60. data/lib/lite/validators/password_validator.rb +1 -1
  61. data/lib/lite/validators/phone_number_validator.rb +1 -1
  62. data/lib/lite/validators/railtie.rb +1 -1
  63. data/lib/lite/validators/sedol_validator.rb +2 -2
  64. data/lib/lite/validators/slug_validator.rb +1 -1
  65. data/lib/lite/validators/ssn_validator.rb +1 -1
  66. data/lib/lite/validators/type_validator.rb +1 -1
  67. data/lib/lite/validators/url_validator.rb +5 -5
  68. data/lib/lite/validators/username_validator.rb +1 -1
  69. data/lib/lite/validators/uuid_validator.rb +1 -1
  70. data/lib/lite/validators/version.rb +1 -1
  71. 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 = [*option_value].any? { |type| type === value.content_type }
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
- [*values]
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 Metrics/LineLength, Style/GuardClause
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 Metrics/LineLength, Style/GuardClause
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,6 +2,6 @@
2
2
 
3
3
  class HexValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.freeze
5
+ REGEXP = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.freeze
6
6
 
7
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class ImeiValidator < BaseValidator
4
4
 
5
- REGEXP ||= /\A[\d\.\:\-\s]+\z/i.freeze
5
+ REGEXP = /\A[\d.:\-\s]+\z/i.freeze
6
6
 
7
7
  private
8
8
 
@@ -4,7 +4,7 @@ require 'resolv'
4
4
 
5
5
  class IpAddressValidator < BaseValidator
6
6
 
7
- REGEXP ||= {
7
+ REGEXP = {
8
8
  ipv4: Resolv::IPv4::Regex,
9
9
  ipv6: Resolv::IPv6::Regex
10
10
  }.freeze
@@ -2,7 +2,7 @@
2
2
 
3
3
  class IsbnValidator < BaseValidator
4
4
 
5
- CHARACTERS ||= %w[
5
+ CHARACTERS = %w[
6
6
  0 1 2 3 4 5 6 7 8 9 x
7
7
  ].freeze
8
8
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  class IsinValidator < BaseValidator
4
4
 
5
- # rubocop:disable Metrics/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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E|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.inject(&:+)
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
- /^([\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
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  class NameValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^([A-Za-z'"-]+\s+){1,4}[A-Za-z'"-]*\z/.freeze
5
+ REGEXP = /^([A-Za-z'"-]+\s+){1,4}[A-Za-z'"-]*\z/.freeze
6
6
 
7
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class PasswordValidator < BaseValidator
4
4
 
5
- REGEXP ||= {
5
+ REGEXP = {
6
6
  strong: /\A(?=.{4,255})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[[:^alnum:]])/x,
7
7
  weak: /^[A-Za-z0-9.,<>:;!@#$%^&*?_~-]{1,255}$/
8
8
  }.freeze
@@ -2,6 +2,6 @@
2
2
 
3
3
  class PhoneNumberValidator < BaseValidator
4
4
 
5
- REGEXP ||= %r{^[0-9+\(\)#\.\s/ext-]+$}.freeze
5
+ REGEXP = %r{^[0-9+()#.\s/ext-]+$}.freeze
6
6
 
7
7
  end
@@ -8,7 +8,7 @@ module Lite
8
8
 
9
9
  initializer 'lite-validators' do |app|
10
10
  Lite::Validators::Railtie.instance_eval do
11
- [app.config.i18n.available_locales].flatten.each do |locale|
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
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  class SedolValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^([A-Z0-9]{6})(\d{1})$/.freeze
6
- WEIGHTS ||= [
5
+ REGEXP = /^([A-Z0-9]{6})(\d{1})$/.freeze
6
+ WEIGHTS = [
7
7
  1, 3, 1, 7, 3, 9, 1
8
8
  ].freeze
9
9
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  class SlugValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^[A-Za-z0-9_-]+$/i.freeze
5
+ REGEXP = /^[A-Za-z0-9_-]+$/i.freeze
6
6
 
7
7
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  class SsnValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/.freeze
5
+ REGEXP = /^\A(\d{3}-\d{2}-\d{4}|\d{9})\Z$/.freeze
6
6
 
7
7
  end
@@ -34,7 +34,7 @@ class TypeValidator < BaseValidator
34
34
  if is_or_is_not == Boolean
35
35
  value.is_a?(TrueClass) || value.is_a?(FalseClass)
36
36
  else
37
- [*is_or_is_not].any? { |klass| value.is_a?(klass) }
37
+ Array(is_or_is_not).any? { |klass| value.is_a?(klass) }
38
38
  end
39
39
  end
40
40
 
@@ -4,7 +4,7 @@ require 'uri'
4
4
 
5
5
  class UrlValidator < BaseValidator
6
6
 
7
- SCHEMES ||= %w[
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 = [*options[:domain]].any? { |domain| value_downcased.end_with?(".#{domain.downcase}") }
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 = [*scheme].any? { |sch| value_downcased == sch.to_s.downcase }
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,6 +2,6 @@
2
2
 
3
3
  class UsernameValidator < BaseValidator
4
4
 
5
- REGEXP ||= /^[a-z0-9_-]{1,255}$/.freeze
5
+ REGEXP = /^[A-Za-z0-9._-]{1,255}$/.freeze
6
6
 
7
7
  end
@@ -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,
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Validators
5
5
 
6
- VERSION ||= '1.0.5'
6
+ VERSION = '1.1.2'
7
7
 
8
8
  end
9
9
  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.0.5
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: 2019-09-06 00:00:00.000000000 Z
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.0.4
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: []