validation_profiler 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd242f26877fb5954baa686b282171c4a23140bf62b9c3aba54b852113e1b010
|
4
|
+
data.tar.gz: 322672ae856dc72c33b2a7a91a0301db199d915c92d40f692781ac8318640011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a65c9098384d2ea03032be86c4b849c3a4d3f3ab21f8a945218e2690a39a076167bf8eb36b67a1f2b3ae835a2a1e762fa5a730b1ed6c694be3d10675a77039fe
|
7
|
+
data.tar.gz: 01bf3313e874ceb2fd4165007289d38350ced6be514c9208a54e6b0d96131b159df55f5739641847ced169fe964b70b6285805090bd9397600286b42ea3894ed
|
@@ -1,50 +1,47 @@
|
|
1
1
|
module ValidationProfiler
|
2
2
|
module Rules
|
3
|
+
# ListValidationRule class
|
3
4
|
class ListValidationRule < ValidationProfiler::Rules::ValidationRule
|
4
|
-
|
5
5
|
def error_message(field, attributes = {}, parent = nil)
|
6
|
-
|
7
6
|
field_name = field.to_s
|
8
|
-
|
9
|
-
field_name = "#{parent.to_s}.#{field.to_s}"
|
10
|
-
end
|
7
|
+
field_name = "#{parent}.#{field}" unless parent.nil?
|
11
8
|
|
12
|
-
|
13
|
-
if attributes[:message] == nil
|
14
|
-
#no custom error message has been specified so create the default message.
|
9
|
+
if attributes[:message].nil?
|
15
10
|
"#{field_name} is not an accepted value."
|
16
11
|
else
|
17
12
|
attributes[:message]
|
18
13
|
end
|
19
14
|
end
|
20
15
|
|
21
|
-
|
22
16
|
def validate(obj, field, attributes = {}, parent = nil)
|
23
|
-
|
24
|
-
#attempt to get the field value from the object
|
25
17
|
field_value = get_field_value(obj, field)
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
if field_value == nil
|
32
|
-
return false
|
33
|
-
end
|
19
|
+
return true unless is_required?(field_value, attributes)
|
20
|
+
return false if field_value.nil?
|
34
21
|
|
35
22
|
list = attributes[:list]
|
36
|
-
|
37
|
-
raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ListValidationRule, field)
|
38
|
-
end
|
23
|
+
regex = attributes[:regex]
|
39
24
|
|
40
|
-
if
|
41
|
-
return false
|
42
|
-
end
|
25
|
+
raise_invalid_exception!(field) if regex.nil? && list.nil?
|
43
26
|
|
44
|
-
|
27
|
+
if list
|
28
|
+
raise_invalid_exception!(field) unless list.is_a?(Array)
|
29
|
+
return false unless list.include?(field_value)
|
30
|
+
elsif regex
|
31
|
+
field_value.each do |value|
|
32
|
+
return false unless value =~ regex
|
33
|
+
end
|
34
|
+
end
|
45
35
|
|
36
|
+
true
|
46
37
|
end
|
47
38
|
|
39
|
+
private
|
40
|
+
|
41
|
+
def raise_invalid_exception!(field)
|
42
|
+
raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
|
43
|
+
.new(ValidationProfiler::Rules::ListValidationRule, field)
|
44
|
+
end
|
48
45
|
end
|
49
46
|
end
|
50
|
-
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sage One
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
|
144
|
-
rubygems_version: 2.7.7
|
143
|
+
rubygems_version: 3.0.2
|
145
144
|
signing_key:
|
146
145
|
specification_version: 4
|
147
146
|
summary: A Validation framework for creating validation profiles, allowing for the
|