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: 91535ba345c6a0bd0054c4bf41d535e933fed864f19e2bd28b84a0d5c459a4b3
4
- data.tar.gz: 96ecb4ee6c75bdca5dd536964e79120e35d1733ed31e6711bc86bf9f54de9052
3
+ metadata.gz: cd242f26877fb5954baa686b282171c4a23140bf62b9c3aba54b852113e1b010
4
+ data.tar.gz: 322672ae856dc72c33b2a7a91a0301db199d915c92d40f692781ac8318640011
5
5
  SHA512:
6
- metadata.gz: b32686a6c08567f043be516baf9389911d13a0e940d4e57e5df752c4345b88fbb4360723cf3ef9c0bb1ebd199bc0e4ca088fb08edfd4b52591561a4fcfdeed41
7
- data.tar.gz: ab4d1e452e567edce9c30b1637d211f422eb179be236dbf2cf67944ee8f93fc2a8129b2fcde35c4d514d0861621a3f7ab30406cb010bc1e85d73729f521c77a9
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
- if parent != nil
9
- field_name = "#{parent.to_s}.#{field.to_s}"
10
- end
7
+ field_name = "#{parent}.#{field}" unless parent.nil?
11
8
 
12
- #check if a custom error message has been specified in the attributes
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
- if !is_required?(field_value, attributes)
28
- return true
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
- if list == nil || !list.is_a?(Array)
37
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ListValidationRule, field)
38
- end
23
+ regex = attributes[:regex]
39
24
 
40
- if !list.include?(field_value)
41
- return false
42
- end
25
+ raise_invalid_exception!(field) if regex.nil? && list.nil?
43
26
 
44
- return true
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
@@ -1,5 +1,5 @@
1
1
  # Namespace
2
2
  module ValidationProfiler
3
3
  # :nodoc:
4
- VERSION = '1.5.0'.freeze
4
+ VERSION = '1.6.0'.freeze
5
5
  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.5.0
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: 2018-05-18 00:00:00.000000000 Z
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
- rubyforge_project:
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