validation_profiler 1.3.4 → 1.3.5

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: e81208909d259403e8b90697aeed8ef8bcd0d66e
4
- data.tar.gz: c26fabf37e6cc9ff74a90bde7e5b88161e303058
3
+ metadata.gz: 7829ec1df6578a2bfe80d7724bd7fadce92494f5
4
+ data.tar.gz: b196fe267a544e1046774a9bbcb6428bc537a5b7
5
5
  SHA512:
6
- metadata.gz: ed8245b2cc2d4aac5a32f9fc96adb0284bfc05a4c1df509e84b0339bcc79f5e8b77c019a476683257c7cdd407305f5cd31e217618c05b6f18a55720467edfa56
7
- data.tar.gz: b75cc8fa44bf2265728f75101e9117c47787e107d6acb84d0cb7a235156f392528b6f69e745f0c1ceca09d942335a40aef64ce8e90b248febbe6a0f997b23737
6
+ metadata.gz: 78d04018153cc0434f32436b1d42b1d4cde2ea409906d25dec22f1b20c3c603c2e7716101ae35bedba91359d0f15c218f3650dca3e1d3608891fb805e3b4c414
7
+ data.tar.gz: cae3746d4cd3ac17ba7fa5c827073f51cfc84ca3c0d038fc7c2e11c9970c8e1e475cb619e2e53113272a873ed9957a8899f1592aea9a449bc80feeffb5b49db5
@@ -48,4 +48,4 @@ module ValidationProfiler
48
48
 
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -1,43 +1,43 @@
1
1
  module ValidationProfiler
2
2
  module Rules
3
3
  class ValidationRule
4
-
5
4
  def get_field_value(obj, field)
6
- #attempt to get the field value from the object
5
+ # attempt to get the field value from the object
7
6
  field_value = nil
8
- #check if the object is a hash
7
+
8
+ # check if the object is a hash
9
9
  if obj.is_a?(Hash)
10
10
  if obj.has_key?(field)
11
- #get the field value
11
+ # get the field value
12
12
  field_value = obj[field]
13
13
  elsif obj.has_key?(field.to_s)
14
14
  field_value = obj[field.to_s]
15
15
  end
16
16
  else
17
- #if the object does not contain the specified field raise an exception
18
- if !obj.respond_to?(field)
19
- raise ValidationProfiler::Exceptions::FieldNotFound.new(field)
20
- end
17
+ # if the object does not contain the specified field raise an exception
18
+ raise ValidationProfiler::Exceptions::FieldNotFound, field unless obj.respond_to?(field)
21
19
 
22
- #get the field value
20
+ # get the field value
23
21
  field_value = obj.send(field)
24
22
  end
25
23
  end
26
24
 
27
25
  def is_required?(field_value, attributes = {})
28
26
  required = attributes[:required]
29
- if required == nil
30
- required = true
31
- end
27
+ required = true if required.nil?
32
28
 
33
- #check if the field is required
34
- if field_value == nil && required == false
35
- return false
36
- else
37
- return true
38
- end
29
+ # check if the field is required
30
+ return false if required_field?(field_value, required)
31
+ true
39
32
  end
40
33
 
34
+ private
35
+
36
+ def required_field?(field_value, required)
37
+ (field_value.nil? ||
38
+ (field_value.respond_to?(:empty?) && field_value.empty?)) &&
39
+ !required
40
+ end
41
41
  end
42
42
  end
43
- end
43
+ 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.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage One
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-05 00:00:00.000000000 Z
11
+ date: 2017-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler