validation_profiler 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3adc3c07f42748f3843a6e55ffdc0c419a7e5d0
4
- data.tar.gz: b4dc8db3b8abc579483ecbfd686dee32a1630fbd
3
+ metadata.gz: 3381f780d5f74c979b4fb6900070803ac626b45b
4
+ data.tar.gz: 1a127233754e44b8a23a5ff0bd5bb88b1319d19e
5
5
  SHA512:
6
- metadata.gz: 77a8016f6acd556a3ae5043ac0f8521294241bbe61e5912ed4b6e2c14bf49f6fa9599d20af6fe3df58bbd0ce547020cc8f6167e231772ecc9bcfb58b356ab95d
7
- data.tar.gz: 32fa0971dc9752625b681f05c122ed2576c44e3d3543109aca5eab50106df5bf48a15a84f8eb743238ea053accc171aee379d5c75a9c3690dc5d513cfc2c9d18
6
+ metadata.gz: 305a7a001b7bf0a378a467032311a94e1dfc5dde3d2d251dfa2323393212ed78c89ac6d68dc94f2241aef000862333f5add068eb33a6eb0c19174311f985f052
7
+ data.tar.gz: 78926ac474b0a798a90fda96bba24603735f4552b5a10de723f08e2a22d7edf2912ed719214c960045a311925e9323e5c6ed04385a2402c34da1ea4a64a3d370
@@ -19,6 +19,7 @@ require_relative 'rules/date_validation_rule'
19
19
  require_relative 'rules/time_validation_rule'
20
20
  require_relative 'rules/integer_validation_rule'
21
21
  require_relative 'rules/decimal_validation_rule'
22
+ require_relative 'rules/guid_validation_rule'
22
23
 
23
24
 
24
25
  ################################
@@ -0,0 +1,57 @@
1
+ module ValidationProfiler
2
+ module Rules
3
+ class GuidValidationRule < ValidationProfiler::Rules::ValidationRule
4
+
5
+ def error_message(field, attributes = {}, parent = nil)
6
+
7
+ field_name = field.to_s
8
+ if parent != nil
9
+ field_name = "#{parent.to_s}.#{field.to_s}"
10
+ end
11
+
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.
15
+ "#{field_name} is not a valid Guid"
16
+ else
17
+ attributes[:message]
18
+ end
19
+ end
20
+
21
+
22
+ def validate(obj, field, attributes = {}, parent = nil)
23
+
24
+ #attempt to get the field value from the object
25
+ field_value = get_field_value(obj, field)
26
+
27
+ if !is_required?(field_value, attributes)
28
+ return true
29
+ end
30
+
31
+ field_value = field_value.to_s
32
+
33
+ if attributes[:hyphens] == true && attributes[:brackets] == true
34
+ if (field_value =~ /^[{(]?[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$/i) != 0
35
+ return false
36
+ end
37
+ elsif attributes[:hyphens] == true
38
+ if (field_value =~ /^?[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}?$/i) != 0
39
+ return false
40
+ end
41
+ elsif attributes[:brackets] == true
42
+ if (field_value =~ /^[{(]?[0-9A-F]{8}?([0-9A-F]{4}?){3}[0-9A-F]{12}[)}]?$/i) != 0
43
+ return false
44
+ end
45
+ else
46
+ if (field_value =~ /^?[0-9A-F]{8}?([0-9A-F]{4}?){3}[0-9A-F]{12}?$/i) != 0
47
+ return false
48
+ end
49
+ end
50
+
51
+ return true
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -71,6 +71,7 @@ module ValidationProfiler
71
71
  @rules.push({ key: :time, instance: ValidationProfiler::Rules::TimeValidationRule.new })
72
72
  @rules.push({ key: :int, instance: ValidationProfiler::Rules::IntegerValidationRule.new })
73
73
  @rules.push({ key: :decimal, instance: ValidationProfiler::Rules::DecimalValidationRule.new })
74
+ @rules.push({ key: :guid, instance: ValidationProfiler::Rules::GuidValidationRule.new })
74
75
 
75
76
  end
76
77
 
@@ -1,3 +1,3 @@
1
1
  module ValidationProfiler
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage
@@ -90,6 +90,7 @@ files:
90
90
  - lib/validation_profiler/rules/date_validation_rule.rb
91
91
  - lib/validation_profiler/rules/decimal_validation_rule.rb
92
92
  - lib/validation_profiler/rules/email_validation_rule.rb
93
+ - lib/validation_profiler/rules/guid_validation_rule.rb
93
94
  - lib/validation_profiler/rules/integer_validation_rule.rb
94
95
  - lib/validation_profiler/rules/length_validation_rule.rb
95
96
  - lib/validation_profiler/rules/list_validation_rule.rb