active_validation 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.reek.yml +23 -0
- data/.rubocop.yml +2 -0
- data/active_validation.gemspec +3 -5
- data/lib/active_validation/validators/alpha_numeric_validator.rb +1 -0
- data/lib/active_validation/validators/alpha_validator.rb +1 -0
- data/lib/active_validation/validators/base64_validator.rb +1 -0
- data/lib/active_validation/validators/boolean_validator.rb +1 -0
- data/lib/active_validation/validators/coordinate_validator.rb +1 -0
- data/lib/active_validation/validators/credit_card_validator.rb +1 -0
- data/lib/active_validation/validators/csv_validator.rb +8 -3
- data/lib/active_validation/validators/currency_validator.rb +1 -0
- data/lib/active_validation/validators/cusip_validator.rb +1 -0
- data/lib/active_validation/validators/email_validator.rb +1 -0
- data/lib/active_validation/validators/equality_validator.rb +1 -0
- data/lib/active_validation/validators/file_size_validator.rb +4 -0
- data/lib/active_validation/validators/hex_validator.rb +1 -0
- data/lib/active_validation/validators/imei_validator.rb +1 -0
- data/lib/active_validation/validators/ip_validator.rb +1 -0
- data/lib/active_validation/validators/isbn_validator.rb +2 -0
- data/lib/active_validation/validators/isin_validator.rb +1 -0
- data/lib/active_validation/validators/mac_address_validator.rb +1 -0
- data/lib/active_validation/validators/name_validator.rb +1 -0
- data/lib/active_validation/validators/password_validator.rb +1 -0
- data/lib/active_validation/validators/phone_validator.rb +1 -0
- data/lib/active_validation/validators/sedol_validator.rb +1 -0
- data/lib/active_validation/validators/slug_validator.rb +1 -0
- data/lib/active_validation/validators/ssn_validator.rb +1 -0
- data/lib/active_validation/validators/time_zone_validator.rb +1 -0
- data/lib/active_validation/validators/tracking_number_validator.rb +6 -0
- data/lib/active_validation/validators/type_validator.rb +1 -0
- data/lib/active_validation/validators/username_validator.rb +1 -0
- data/lib/active_validation/validators/uuid_validator.rb +1 -0
- data/lib/active_validation/version.rb +1 -1
- metadata +11 -11
- data/.reek +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 186d4480a145fcb49093b26ae4b8ad00594395c8de1cb39377097bdefff0663c
|
4
|
+
data.tar.gz: 455960df6cbd91113b72d699e86c980804cf39e5bfaf63efa93660e22e328b58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90ef02afec2046e5032053c3f184198299bdeba6fdc52160f2d7bf98483089c0f619b90a12d9301c7c743f869f526c6ff60966c792d8df7e6d128994bf87f473
|
7
|
+
data.tar.gz: a09a15b4216829d7a019bbb0c88400e137d3034606f8ee2cd7e273312cf9595520cd0df71c846af3d51a9c7b1ffa7082d682efab0d509e22932582845560d020
|
data/.reek.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
detectors:
|
3
|
+
DataClump:
|
4
|
+
enabled: false
|
5
|
+
DuplicateMethodCall:
|
6
|
+
enabled: false
|
7
|
+
FeatureEnvy:
|
8
|
+
enabled: false
|
9
|
+
IrresponsibleModule:
|
10
|
+
enabled: false
|
11
|
+
MissingSafeMethod:
|
12
|
+
enabled: false
|
13
|
+
NestedIterators:
|
14
|
+
max_allowed_nesting: 2
|
15
|
+
NilCheck:
|
16
|
+
enabled: false
|
17
|
+
RepeatedConditional:
|
18
|
+
enabled: false
|
19
|
+
TooManyStatements:
|
20
|
+
max_statements: 10
|
21
|
+
enabled: false
|
22
|
+
UtilityFunction:
|
23
|
+
enabled: false
|
data/.rubocop.yml
CHANGED
data/active_validation.gemspec
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# coding: utf-8
|
4
|
-
|
5
3
|
lib = File.expand_path('../lib', __FILE__)
|
6
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
5
|
require 'active_validation/version'
|
@@ -27,11 +25,11 @@ Gem::Specification.new do |spec|
|
|
27
25
|
spec.add_runtime_dependency 'activesupport'
|
28
26
|
|
29
27
|
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'fasterer'
|
30
29
|
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'reek'
|
31
31
|
spec.add_development_dependency 'rspec'
|
32
32
|
spec.add_development_dependency 'rspec-rails'
|
33
|
-
spec.add_development_dependency 'shoulda'
|
34
|
-
spec.add_development_dependency 'fasterer'
|
35
|
-
spec.add_development_dependency 'reek'
|
36
33
|
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'shoulda'
|
37
35
|
end
|
@@ -7,6 +7,7 @@ class BooleanValidator < ActiveModel::EachValidator
|
|
7
7
|
|
8
8
|
def validate_each(record, attribute, value)
|
9
9
|
return if TRUE_VALUES.include?(value) || FALSE_VALUES.include?(value)
|
10
|
+
|
10
11
|
record.errors[attribute] <<
|
11
12
|
(options[:message] || I18n.t('active_validation.errors.messages.boolean'))
|
12
13
|
end
|
@@ -33,6 +33,7 @@ class CreditCardValidator < ActiveModel::EachValidator
|
|
33
33
|
|
34
34
|
def validate_each(record, attribute, value)
|
35
35
|
return if valid?(value.to_s, options)
|
36
|
+
|
36
37
|
record.errors[attribute] <<
|
37
38
|
(options[:message] || I18n.t('active_validation.errors.messages.credit_card'))
|
38
39
|
end
|
@@ -32,6 +32,7 @@ class CsvValidator < ActiveModel::EachValidator
|
|
32
32
|
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
33
33
|
|
34
34
|
next unless values.any? { |val| !valid_size?(val, option, option_value) }
|
35
|
+
|
35
36
|
error_text = filtered_options(values).merge!(detect_error_options(option_value))
|
36
37
|
error_text = options[:message] ||
|
37
38
|
I18n.t("active_validation.errors.messages.csv.#{option}", error_text)
|
@@ -51,18 +52,19 @@ class CsvValidator < ActiveModel::EachValidator
|
|
51
52
|
check_options(Range, options.slice(:columns_in, :rows_in))
|
52
53
|
end
|
53
54
|
|
54
|
-
# rubocop:disable Lint/
|
55
|
+
# rubocop:disable Lint/RescueException
|
55
56
|
def valid_extension?(record, attribute, value)
|
56
57
|
value.path.end_with?('.csv')
|
57
|
-
rescue
|
58
|
+
rescue Exception
|
58
59
|
record.errors[attribute] <<
|
59
60
|
(options[:message] || I18n.t('active_validation.errors.messages.csv.not_valid'))
|
60
61
|
false
|
61
62
|
end
|
62
|
-
# rubocop:enable Lint/
|
63
|
+
# rubocop:enable Lint/RescueException
|
63
64
|
|
64
65
|
def parse_values(record, attribute, value)
|
65
66
|
return nil unless valid_extension?(record, attribute, value)
|
67
|
+
|
66
68
|
[CSV.read(value.path)]
|
67
69
|
rescue CSV::MalformedCSVError
|
68
70
|
record.errors[attribute] <<
|
@@ -73,6 +75,7 @@ class CsvValidator < ActiveModel::EachValidator
|
|
73
75
|
def check_options(klass, options)
|
74
76
|
options.each do |option, value|
|
75
77
|
next if value.is_a?(klass) || value.is_a?(Proc)
|
78
|
+
|
76
79
|
raise ArgumentError,
|
77
80
|
":#{option} must be a #{klass.name.to_s.downcase} or a proc"
|
78
81
|
end
|
@@ -83,6 +86,7 @@ class CsvValidator < ActiveModel::EachValidator
|
|
83
86
|
|
84
87
|
return false if size.zero?
|
85
88
|
return option_value.send(CHECKS[option], size) if option_value.is_a?(Range)
|
89
|
+
|
86
90
|
size.send(CHECKS[option], option_value)
|
87
91
|
end
|
88
92
|
|
@@ -94,6 +98,7 @@ class CsvValidator < ActiveModel::EachValidator
|
|
94
98
|
|
95
99
|
def detect_error_options(option_value)
|
96
100
|
return { count: option_value } unless option_value.is_a?(Range)
|
101
|
+
|
97
102
|
{ min: option_value.min, max: option_value.max }
|
98
103
|
end
|
99
104
|
|
@@ -28,6 +28,7 @@ class EqualityValidator < ActiveModel::EachValidator
|
|
28
28
|
|
29
29
|
operator = OPERATORS[operator]
|
30
30
|
return if value.send(operator, record.send(to))
|
31
|
+
|
31
32
|
record.errors[attribute] <<
|
32
33
|
(options[:message] || I18n.t('active_validation.errors.messages.equality', attr: to, operator: operator))
|
33
34
|
end
|
@@ -19,6 +19,7 @@ class FileSizeValidator < ActiveModel::EachValidator
|
|
19
19
|
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
20
20
|
|
21
21
|
next unless values.any? { |val| !valid_size?(val.size, option, option_value) }
|
22
|
+
|
22
23
|
error_text = filtered_options(values).merge!(detect_error_options(option_value))
|
23
24
|
error_text = options[:message] ||
|
24
25
|
I18n.t("active_validation.errors.messages.file_size.#{option}", error_text)
|
@@ -51,6 +52,7 @@ class FileSizeValidator < ActiveModel::EachValidator
|
|
51
52
|
def check_options(klass, options)
|
52
53
|
options.each do |option, value|
|
53
54
|
next if value.is_a?(klass) || value.is_a?(Proc)
|
55
|
+
|
54
56
|
raise ArgumentError,
|
55
57
|
":#{option} must be a #{klass.name.to_s.downcase} or a proc"
|
56
58
|
end
|
@@ -59,6 +61,7 @@ class FileSizeValidator < ActiveModel::EachValidator
|
|
59
61
|
def valid_size?(size, option, option_value)
|
60
62
|
return false if size.nil?
|
61
63
|
return option_value.send(CHECKS[option], size) if option_value.is_a?(Range)
|
64
|
+
|
62
65
|
size.send(CHECKS[option], option_value)
|
63
66
|
end
|
64
67
|
|
@@ -70,6 +73,7 @@ class FileSizeValidator < ActiveModel::EachValidator
|
|
70
73
|
|
71
74
|
def detect_error_options(option_value)
|
72
75
|
return { count: human_size(option_value) } unless option_value.is_a?(Range)
|
76
|
+
|
73
77
|
{ min: human_size(option_value.min), max: human_size(option_value.max) }
|
74
78
|
end
|
75
79
|
|
@@ -6,6 +6,7 @@ class IsbnValidator < ActiveModel::EachValidator
|
|
6
6
|
|
7
7
|
def validate_each(record, attribute, value)
|
8
8
|
return if valid?(value.to_s)
|
9
|
+
|
9
10
|
record.errors[attribute] <<
|
10
11
|
(options[:message] || I18n.t('active_validation.errors.messages.isbn'))
|
11
12
|
end
|
@@ -14,6 +15,7 @@ class IsbnValidator < ActiveModel::EachValidator
|
|
14
15
|
|
15
16
|
def valid_format?(value)
|
16
17
|
return(false) if value.empty?
|
18
|
+
|
17
19
|
value = value.gsub(/-| /, '').downcase.chars
|
18
20
|
|
19
21
|
[10, 13].include?(value.size) && value.all? { |chr| CHARACTERS.include?(chr) }
|
@@ -25,6 +25,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
25
25
|
|
26
26
|
def validate_each(record, attribute, value)
|
27
27
|
return if valid?(value.to_s, options)
|
28
|
+
|
28
29
|
record.errors[attribute] <<
|
29
30
|
(options[:message] || I18n.t('active_validation.errors.messages.tracking_number'))
|
30
31
|
end
|
@@ -36,6 +37,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
36
37
|
define_method("valid_dhl_#{srv}_checksum?") do |val|
|
37
38
|
formula = val.scan(pat).flatten.compact
|
38
39
|
return(false) if formula.empty?
|
40
|
+
|
39
41
|
sequence, check_digit = formula.map(&:to_i)
|
40
42
|
|
41
43
|
(sequence % 7) == check_digit
|
@@ -49,6 +51,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
49
51
|
pattern = CARRIERS_AND_SERVICES[:fedex][:express]
|
50
52
|
formula = value.scan(pattern).flatten.compact
|
51
53
|
return(false) if formula.empty?
|
54
|
+
|
52
55
|
sequence, check_digit = formula
|
53
56
|
|
54
57
|
total = 0
|
@@ -67,6 +70,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
67
70
|
|
68
71
|
formula = val.scan(pat).flatten.compact
|
69
72
|
return(false) if formula.empty?
|
73
|
+
|
70
74
|
sequence, check_digit = formula
|
71
75
|
|
72
76
|
total = 0
|
@@ -89,6 +93,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
89
93
|
pattern = CARRIERS_AND_SERVICES[:fedex][:smart_post]
|
90
94
|
formula = value.scan(pattern).flatten.compact
|
91
95
|
return(false) if formula.empty?
|
96
|
+
|
92
97
|
sequence, check_digit = formula
|
93
98
|
|
94
99
|
total = 0
|
@@ -113,6 +118,7 @@ class TrackingNumberValidator < ActiveModel::EachValidator
|
|
113
118
|
|
114
119
|
formula = val.scan(pat).flatten.compact
|
115
120
|
return(false) if formula.empty?
|
121
|
+
|
116
122
|
sequence, check_digit = formula
|
117
123
|
|
118
124
|
total = 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.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:
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: fasterer
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: reek
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rspec-rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rubocop
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: shoulda
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -174,7 +174,7 @@ files:
|
|
174
174
|
- ".DS_Store"
|
175
175
|
- ".fasterer.yml"
|
176
176
|
- ".gitignore"
|
177
|
-
- ".reek"
|
177
|
+
- ".reek.yml"
|
178
178
|
- ".rspec"
|
179
179
|
- ".rubocop.yml"
|
180
180
|
- ".travis.yml"
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
version: '0'
|
243
243
|
requirements: []
|
244
244
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.
|
245
|
+
rubygems_version: 2.7.7
|
246
246
|
signing_key:
|
247
247
|
specification_version: 4
|
248
248
|
summary: Gem for commonly used validators.
|
data/.reek
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
---
|
2
|
-
DataClump:
|
3
|
-
enabled: false
|
4
|
-
DuplicateMethodCall:
|
5
|
-
enabled: false
|
6
|
-
FeatureEnvy:
|
7
|
-
enabled: false
|
8
|
-
IrresponsibleModule:
|
9
|
-
enabled: false
|
10
|
-
NestedIterators:
|
11
|
-
max_allowed_nesting: 2
|
12
|
-
NilCheck:
|
13
|
-
enabled: false
|
14
|
-
PrimaDonnaMethod:
|
15
|
-
enabled: false
|
16
|
-
RepeatedConditional:
|
17
|
-
enabled: false
|
18
|
-
TooManyStatements:
|
19
|
-
max_statements: 10
|
20
|
-
enabled: false
|
21
|
-
UtilityFunction:
|
22
|
-
enabled: false
|