validation_profiler 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/validation_profiler/rules.rb +1 -0
- data/lib/validation_profiler/rules/date_validation_rule.rb +43 -0
- data/lib/validation_profiler/rules/regex_validation_rule.rb +1 -1
- data/lib/validation_profiler/rules/validation_rule_manager.rb +1 -0
- data/lib/validation_profiler/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a5ccf27cee7ecaa97be549eebfbea7299542a20
|
4
|
+
data.tar.gz: f8b3cd80daa08f6555ec036950ab7e47ea2e8bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
|
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
|
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-
|
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:
|