validation_profiler 1.1.0 → 1.2.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: 8a5ccf27cee7ecaa97be549eebfbea7299542a20
4
- data.tar.gz: f8b3cd80daa08f6555ec036950ab7e47ea2e8bd7
3
+ metadata.gz: b3adc3c07f42748f3843a6e55ffdc0c419a7e5d0
4
+ data.tar.gz: b4dc8db3b8abc579483ecbfd686dee32a1630fbd
5
5
  SHA512:
6
- metadata.gz: 7f766784a63fd2650a76ca9339ad878290e93cea244a773d812653e7fb2377c04e76820116d90bf5bcd313f4bef1b5b4c22f491541890fd2bc4ea1f86195f179
7
- data.tar.gz: 8606fcb4e56a627383d3227ce0f96d0d71808def4df9365ed87093f3bdb6aed45cb5fb17bf725bc72be93298cc15166ff5ab4381dd695956c5db0563ee1ae05a
6
+ metadata.gz: 77a8016f6acd556a3ae5043ac0f8521294241bbe61e5912ed4b6e2c14bf49f6fa9599d20af6fe3df58bbd0ce547020cc8f6167e231772ecc9bcfb58b356ab95d
7
+ data.tar.gz: 32fa0971dc9752625b681f05c122ed2576c44e3d3543109aca5eab50106df5bf48a15a84f8eb743238ea053accc171aee379d5c75a9c3690dc5d513cfc2c9d18
@@ -16,6 +16,9 @@ require_relative 'rules/not_allowed_validation_rule'
16
16
  require_relative 'rules/regex_validation_rule'
17
17
  require_relative 'rules/required_validation_rule'
18
18
  require_relative 'rules/date_validation_rule'
19
+ require_relative 'rules/time_validation_rule'
20
+ require_relative 'rules/integer_validation_rule'
21
+ require_relative 'rules/decimal_validation_rule'
19
22
 
20
23
 
21
24
  ################################
@@ -0,0 +1,46 @@
1
+ require 'bigdecimal'
2
+ module ValidationProfiler
3
+ module Rules
4
+ class DecimalValidationRule < ValidationProfiler::Rules::ValidationRule
5
+
6
+ def error_message(field, attributes = {}, parent = nil)
7
+
8
+ field_name = field.to_s
9
+ if parent != nil
10
+ field_name = "#{parent.to_s}.#{field.to_s}"
11
+ end
12
+
13
+ #check if a custom error message has been specified in the attributes
14
+ if attributes[:message] == nil
15
+ #no custom error message has been specified so create the default message.
16
+ "#{field_name} is not a valid Decimal"
17
+ else
18
+ attributes[:message]
19
+ end
20
+ end
21
+
22
+
23
+ def validate(obj, field, attributes = {}, parent = nil)
24
+
25
+ #attempt to get the field value from the object
26
+ field_value = get_field_value(obj, field)
27
+
28
+ if !is_required?(field_value, attributes)
29
+ return true
30
+ end
31
+
32
+ if !is_valid_decimal?(field_value.to_s)
33
+ return false
34
+ end
35
+
36
+ return true
37
+
38
+ end
39
+
40
+ def is_valid_decimal?(value)
41
+ (value =~ /\A[-+]?\d*\.?\d+\z/) == 0
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ module ValidationProfiler
2
+ module Rules
3
+ class IntegerValidationRule < 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 Integer"
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
+ begin
32
+ Integer(field_value)
33
+ rescue
34
+ return false
35
+ end
36
+
37
+ return true
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,51 @@
1
+ module ValidationProfiler
2
+ module Rules
3
+ class TimeValidationRule < 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 time"
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
+ begin
32
+ if field_value.is_a?(Integer)
33
+ Time.at(field_value)
34
+ else
35
+ begin
36
+ Time.parse(field_value)
37
+ rescue
38
+ Time.at(Integer(field_value))
39
+ end
40
+ end
41
+ rescue
42
+ return false
43
+ end
44
+
45
+ return true
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -68,6 +68,9 @@ module ValidationProfiler
68
68
  @rules.push({ key: :list, instance: ValidationProfiler::Rules::ListValidationRule.new })
69
69
  @rules.push({ key: :child, instance: ValidationProfiler::Rules::ChildValidationRule.new })
70
70
  @rules.push({ key: :date, instance: ValidationProfiler::Rules::DateValidationRule.new })
71
+ @rules.push({ key: :time, instance: ValidationProfiler::Rules::TimeValidationRule.new })
72
+ @rules.push({ key: :int, instance: ValidationProfiler::Rules::IntegerValidationRule.new })
73
+ @rules.push({ key: :decimal, instance: ValidationProfiler::Rules::DecimalValidationRule.new })
71
74
 
72
75
  end
73
76
 
@@ -1,3 +1,3 @@
1
1
  module ValidationProfiler
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-12 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,9 @@ files:
88
88
  - lib/validation_profiler/rules/child_validation_rule.rb
89
89
  - lib/validation_profiler/rules/condition_validation_rule.rb
90
90
  - lib/validation_profiler/rules/date_validation_rule.rb
91
+ - lib/validation_profiler/rules/decimal_validation_rule.rb
91
92
  - lib/validation_profiler/rules/email_validation_rule.rb
93
+ - lib/validation_profiler/rules/integer_validation_rule.rb
92
94
  - lib/validation_profiler/rules/length_validation_rule.rb
93
95
  - lib/validation_profiler/rules/list_validation_rule.rb
94
96
  - lib/validation_profiler/rules/match_validation_rule.rb
@@ -97,6 +99,7 @@ files:
97
99
  - lib/validation_profiler/rules/not_allowed_validation_rule.rb
98
100
  - lib/validation_profiler/rules/regex_validation_rule.rb
99
101
  - lib/validation_profiler/rules/required_validation_rule.rb
102
+ - lib/validation_profiler/rules/time_validation_rule.rb
100
103
  - lib/validation_profiler/rules/validation_rule.rb
101
104
  - lib/validation_profiler/rules/validation_rule_manager.rb
102
105
  - lib/validation_profiler/version.rb