validation_profiler 1.0.1 → 1.1.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: 0e73f7df9dd6ae5d0a38f0b5289eae7fcf5c5169
4
- data.tar.gz: dc60c99963b059bbdbe24b904f3817e4ecb56661
3
+ metadata.gz: 8a5ccf27cee7ecaa97be549eebfbea7299542a20
4
+ data.tar.gz: f8b3cd80daa08f6555ec036950ab7e47ea2e8bd7
5
5
  SHA512:
6
- metadata.gz: 2755117a1870bbf2869486555eaaf05cb5f3ef03fe9727e060248d37afdc36224d380d00ae2a1e0360c19b590c2d1f0be3030883bb842fedecbba820290a1903
7
- data.tar.gz: c7c33f53245c9514bd070bbee7d16002e8bb52741f9562561535659b9199dd17e1341504069adf8f566e678beb85fd2e7c134d44db81df8e157e6fc02ac3c5cd
6
+ metadata.gz: 7f766784a63fd2650a76ca9339ad878290e93cea244a773d812653e7fb2377c04e76820116d90bf5bcd313f4bef1b5b4c22f491541890fd2bc4ea1f86195f179
7
+ data.tar.gz: 8606fcb4e56a627383d3227ce0f96d0d71808def4df9365ed87093f3bdb6aed45cb5fb17bf725bc72be93298cc15166ff5ab4381dd695956c5db0563ee1ae05a
@@ -15,6 +15,7 @@ require_relative 'rules/min_validation_rule'
15
15
  require_relative 'rules/not_allowed_validation_rule'
16
16
  require_relative 'rules/regex_validation_rule'
17
17
  require_relative 'rules/required_validation_rule'
18
+ require_relative 'rules/date_validation_rule'
18
19
 
19
20
 
20
21
  ################################
@@ -0,0 +1,43 @@
1
+ module ValidationProfiler
2
+ module Rules
3
+ class DateValidationRule < 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 date"
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
+ Date.parse(field_value)
33
+ rescue => e
34
+ return false
35
+ end
36
+
37
+ return true
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -12,7 +12,7 @@ module ValidationProfiler
12
12
  #check if a custom error message has been specified in the attributes
13
13
  if attributes[:message] == nil
14
14
  #no custom error message has been specified so create the default message.
15
- "#{field_name} is not a valid"
15
+ "#{field_name} is not valid"
16
16
  else
17
17
  attributes[:message]
18
18
  end
@@ -67,6 +67,7 @@ module ValidationProfiler
67
67
  @rules.push({ key: :not_allowed, instance: ValidationProfiler::Rules::NotAllowedValidationRule.new })
68
68
  @rules.push({ key: :list, instance: ValidationProfiler::Rules::ListValidationRule.new })
69
69
  @rules.push({ key: :child, instance: ValidationProfiler::Rules::ChildValidationRule.new })
70
+ @rules.push({ key: :date, instance: ValidationProfiler::Rules::DateValidationRule.new })
70
71
 
71
72
  end
72
73
 
@@ -1,3 +1,3 @@
1
1
  module ValidationProfiler
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.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.0.1
4
+ version: 1.1.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-06-17 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - lib/validation_profiler/rules.rb
88
88
  - lib/validation_profiler/rules/child_validation_rule.rb
89
89
  - lib/validation_profiler/rules/condition_validation_rule.rb
90
+ - lib/validation_profiler/rules/date_validation_rule.rb
90
91
  - lib/validation_profiler/rules/email_validation_rule.rb
91
92
  - lib/validation_profiler/rules/length_validation_rule.rb
92
93
  - lib/validation_profiler/rules/list_validation_rule.rb
@@ -125,4 +126,3 @@ specification_version: 4
125
126
  summary: A Validation framework for creating validation profiles, allowing for the
126
127
  separation & reuse of validation logic from the object being validated.
127
128
  test_files: []
128
- has_rdoc: