validation_profiler 1.3.5 → 1.4.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
  SHA1:
3
- metadata.gz: 7829ec1df6578a2bfe80d7724bd7fadce92494f5
4
- data.tar.gz: b196fe267a544e1046774a9bbcb6428bc537a5b7
3
+ metadata.gz: b30c9295a13e83dfcf6acbf158e520f1679ee1cd
4
+ data.tar.gz: b096548df1dceba53873a7bd3b165d9476c72d68
5
5
  SHA512:
6
- metadata.gz: 78d04018153cc0434f32436b1d42b1d4cde2ea409906d25dec22f1b20c3c603c2e7716101ae35bedba91359d0f15c218f3650dca3e1d3608891fb805e3b4c414
7
- data.tar.gz: cae3746d4cd3ac17ba7fa5c827073f51cfc84ca3c0d038fc7c2e11c9970c8e1e475cb619e2e53113272a873ed9957a8899f1592aea9a449bc80feeffb5b49db5
6
+ metadata.gz: 62c0c1e1f28d8a74fe83ba003924d33f4949e920b1a4d7e1fd7933fe47505c7c695b89c6440d9728ae2b5258660a932f3f1c019ec4ac5699488969096c1c3e32
7
+ data.tar.gz: a6ba25274094599fc17fe07b4a5a42599a853d53172ef7c51081c031c7da82bbe93f00590c00d7cd835353933e594d3a3e9f198897791f97d4aaba658f6691ef
@@ -1,93 +1,74 @@
1
1
  module ValidationProfiler
2
2
  module Rules
3
+ # Defines the ConditionValidationRule class
3
4
  class ConditionValidationRule < 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
+ # check if a custom error message has been specified in the attributes
10
+ if attributes[:message].nil?
11
+ # no custom error message has been specified so create the default message.
15
12
  "#{field_name} is not valid"
16
13
  else
17
14
  attributes[:message]
18
15
  end
19
16
  end
20
17
 
21
-
22
- def validate(obj, field, attributes, parent = nil)
23
-
24
- #attempt to get the field value from the object
18
+ def validate(obj, field, attributes, _parent = nil)
19
+ # attempt to get the field value from the object
25
20
  value = get_field_value(obj, field)
26
21
 
27
22
  condition_field = attributes[:condition_field]
28
- if condition_field == nil
29
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ConditionValidationRule, field)
23
+ if condition_field.nil?
24
+ raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
25
+ .new(ValidationProfiler::Rules::ConditionValidationRule, field)
30
26
  end
31
27
 
32
28
  condition_value = attributes[:condition_value]
33
- if condition_value == nil
34
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ConditionValidationRule, field)
29
+ if condition_value.nil?
30
+ raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
31
+ .new(ValidationProfiler::Rules::ConditionValidationRule, field)
35
32
  end
36
33
 
37
34
  condition_expression = attributes[:condition_expression]
38
- if condition_expression == nil
39
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ConditionValidationRule, field)
35
+ if condition_expression.nil?
36
+ raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
37
+ .new(ValidationProfiler::Rules::ConditionValidationRule, field)
40
38
  end
41
39
 
42
40
  field_expression = attributes[:field_expression]
43
- if field_expression == nil
44
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ConditionValidationRule, field)
41
+ if field_expression.nil?
42
+ raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
43
+ .new(ValidationProfiler::Rules::ConditionValidationRule, field)
45
44
  end
46
45
 
47
46
  field_value = attributes[:field_value]
48
- if field_value == nil
49
- raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes.new(ValidationProfiler::Rules::ConditionValidationRule, field)
47
+ if field_value.nil?
48
+ raise ValidationProfiler::Exceptions::InvalidValidationRuleAttributes
49
+ .new(ValidationProfiler::Rules::ConditionValidationRule, field)
50
50
  end
51
51
 
52
- if !is_required?(value, attributes)
53
- return true
54
- end
52
+ return true unless is_required?(value, attributes)
55
53
 
56
54
  condition_field_value = get_field_value(obj, condition_field)
57
55
 
58
- #check if the condition is valid
56
+ # check if the condition is valid
59
57
  if confirm_expression?(condition_field_value, condition_expression, condition_value)
60
- #check if the field value is correct for the condition
61
- if confirm_expression?(value, field_expression, field_value)
62
- return true
63
- else
64
- return false
65
- end
58
+ # check if the field value is correct for the condition
59
+ return false unless confirm_expression?(value, field_expression, field_value)
60
+ return true
66
61
  end
67
62
 
68
- return true
69
-
63
+ true
70
64
  end
71
65
 
72
66
  def confirm_expression?(value_a, expression, value_b)
73
67
  a = value_a
74
68
  b = value_b
75
69
 
76
- if value_a.is_a?(String)
77
- a = "'#{value_a}'"
78
- elsif value_a == nil
79
- a = 'nil'
80
- end
81
-
82
- if value_b.is_a?(String)
83
- b = "'#{value_b}'"
84
- elsif value_b == nil
85
- b = 'nil'
86
- end
87
-
88
- eval("#{a} #{expression} #{b}")
70
+ a.public_send(expression.to_s, b)
89
71
  end
90
-
91
72
  end
92
73
  end
93
- end
74
+ 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.3.5
4
+ version: 1.4.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: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.6.13
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: A Validation framework for creating validation profiles, allowing for the