validation_profiler 1.3.1 → 1.3.2

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: d2b5014c12eb5cb06db2536e8f16de6b5632cb96
4
- data.tar.gz: f318a25ed57f3517e2a23493deccbd974d9f10b8
3
+ metadata.gz: 534b05801ef07e861665143c2a16efff8c79ebbc
4
+ data.tar.gz: 06a6f117d9b4ef0d1070ea22841eaa8e526c5076
5
5
  SHA512:
6
- metadata.gz: d77cf55275d066bb5d083a8eb4039c82a6b57fdd52b44c452b2555425e892828ca8bcde274381e230eb895c5ab9fe708fa51a97457f2b72eb9764963847b96b1
7
- data.tar.gz: 60cb934b0e2767f59c3b7ac78b0b6b1c75725a189dde6d17fa05fc2cde2b69d51c7726002f2d0c55053e16a751465f871a73d12bb4d05b6eeff0a3dd0c69690e
6
+ metadata.gz: 6eb8b3d613484ac3cb15a6865161e9453f17e59ceb768a3221b5cd13f2cb82d05e352ecba8775da6a889c1d452d50263452333e29267c9ac124ed9f49707fddf
7
+ data.tar.gz: 90342abc72ddf353a8e119320fce4dedffd7ff1353ab948a83c462c5084d2d8719bc3a3fc21b05570e000015a6b2904b4c94a6acf6e3673a2132607acccc163a
@@ -1,86 +1,6 @@
1
- require 'validation_profiler/version'
1
+ require 'validation_profiler/class_methods'
2
2
  require 'validation_profiler/exceptions'
3
3
  require 'validation_profiler/rules'
4
+ require 'validation_profiler/manager'
5
+ require 'validation_profiler/manager_result'
4
6
 
5
- class Class
6
-
7
- # Specifies a validation rule to use within a validation profile.
8
- #
9
- # @param field [Symbol] The name of the field to validate
10
- # @param rule [Symbol] The name of the validation rule to use
11
- # @param attributes [Hash] [Optional] A has containing the validation rule options
12
- def validates(field, rule, attributes = {})
13
-
14
- if !self.class_variable_defined?(:@@validation_rules)
15
- self.class_variable_set(:@@validation_rules, [])
16
- end
17
-
18
- validation_rules = self.class_variable_get(:@@validation_rules)
19
- validation_rules.push({ name: rule, field: field, attributes: attributes })
20
-
21
- self.class_variable_set(:@@validation_rules, validation_rules)
22
-
23
- end
24
-
25
- def self.sides
26
- @@sides
27
- end
28
-
29
- end
30
-
31
- module ValidationProfiler
32
- class Manager
33
-
34
- # Called to validate an object against a validation profile.
35
- #
36
- # @param obj [Object] The object to validate
37
- # @param profile [ClassName] The class name of the validation profile to validate against
38
- #
39
- # @return [ValidationManagerResult] The result of the validation
40
- def validate(obj, profile, parent = nil)
41
-
42
- result = ValidationProfiler::ManagerResult.new
43
-
44
- validation_rules = profile.class_variable_get(:@@validation_rules)
45
-
46
- validation_rules.each do |r|
47
-
48
- if ValidationProfiler::Rules::Manager.instance == nil
49
- ValidationProfiler::Rules::Manager.new
50
- end
51
-
52
- rule = ValidationProfiler::Rules::Manager.instance.get_rule(r[:name])
53
- outcome = rule.validate(obj, r[:field], r[:attributes], parent)
54
-
55
- if outcome.is_a?(ValidationProfiler::ManagerResult) && !outcome.outcome
56
- result.errors = result.errors + outcome.errors
57
- result.outcome = false
58
- elsif !outcome
59
- result.outcome = false
60
- result.errors.push({ field: r[:field], message: rule.error_message(r[:field], r[:attributes], parent) })
61
- end
62
-
63
- end
64
-
65
- result
66
-
67
- end
68
-
69
- end
70
-
71
- # This is used to specify validation results from the #validate method of the Validation Manager
72
- class ManagerResult
73
-
74
- # @!attribute outcome
75
- # @return [Boolean] The outcome of the validation.
76
- attr_accessor :outcome
77
- # @!attribute errors
78
- # @return [Array[{:field, :error_message}]] An array of field errors that occurred during validation.
79
- attr_accessor :errors
80
-
81
- def initialize
82
- @errors = []
83
- @outcome = true
84
- end
85
- end
86
- end
@@ -0,0 +1,44 @@
1
+ class Class
2
+
3
+ #[DEPRECIATED] do not use, please use 'extend ValidationProfiler' instead
4
+ # Specifies a validation rule to use within a validation profile.
5
+ #
6
+ # @param field [Symbol] The name of the field to validate
7
+ # @param rule [Symbol] The name of the validation rule to use
8
+ # @param attributes [Hash] [Optional] A has containing the validation rule options
9
+ def validates(field, rule, attributes = {})
10
+
11
+ puts "[#{self.class}] - Method depreciated. Please use 'extend ValidationProfiler' in your validation profile class to access the 'validates' method."
12
+
13
+ if !self.class_variable_defined?(:@@validation_rules)
14
+ self.class_variable_set(:@@validation_rules, [])
15
+ end
16
+
17
+ validation_rules = self.class_variable_get(:@@validation_rules)
18
+ validation_rules.push({ name: rule, field: field, attributes: attributes })
19
+
20
+ self.class_variable_set(:@@validation_rules, validation_rules)
21
+
22
+ end
23
+
24
+ end
25
+
26
+ module ValidationProfiler
27
+ # Specifies a validation rule to use within a validation profile.
28
+ #
29
+ # @param field [Symbol] The name of the field to validate
30
+ # @param rule [Symbol] The name of the validation rule to use
31
+ # @param attributes [Hash] [Optional] A has containing the validation rule options
32
+ def validates(field, rule, attributes = {})
33
+
34
+ if !self.class_variable_defined?(:@@validation_rules)
35
+ self.class_variable_set(:@@validation_rules, [])
36
+ end
37
+
38
+ validation_rules = self.class_variable_get(:@@validation_rules)
39
+ validation_rules.push({ name: rule, field: field, attributes: attributes })
40
+
41
+ self.class_variable_set(:@@validation_rules, validation_rules)
42
+
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ module ValidationProfiler
2
+ class Manager
3
+
4
+ # Called to validate an object against a validation profile.
5
+ #
6
+ # @param obj [Object] The object to validate
7
+ # @param profile [ClassName] The class name of the validation profile to validate against
8
+ #
9
+ # @return [ValidationManagerResult] The result of the validation
10
+ def validate(obj, profile, parent = nil)
11
+
12
+ result = ValidationProfiler::ManagerResult.new
13
+
14
+ validation_rules = profile.class_variable_get(:@@validation_rules)
15
+
16
+ validation_rules.each do |r|
17
+
18
+ if ValidationProfiler::Rules::Manager.instance == nil
19
+ ValidationProfiler::Rules::Manager.new
20
+ end
21
+
22
+ rule = ValidationProfiler::Rules::Manager.instance.get_rule(r[:name])
23
+ outcome = rule.validate(obj, r[:field], r[:attributes], parent)
24
+
25
+ if outcome.is_a?(ValidationProfiler::ManagerResult) && !outcome.outcome
26
+ result.errors = result.errors + outcome.errors
27
+ result.outcome = false
28
+ elsif !outcome
29
+ result.outcome = false
30
+ result.errors.push({ field: r[:field], message: rule.error_message(r[:field], r[:attributes], parent) })
31
+ end
32
+
33
+ end
34
+
35
+ result
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module ValidationProfiler
2
+ # This is used to specify validation results from the #validate method of the Validation Manager
3
+ class ManagerResult
4
+
5
+ # @!attribute outcome
6
+ # @return [Boolean] The outcome of the validation.
7
+ attr_accessor :outcome
8
+ # @!attribute errors
9
+ # @return [Array[{:field, :error_message}]] An array of field errors that occurred during validation.
10
+ attr_accessor :errors
11
+
12
+ def initialize
13
+ @errors = []
14
+ @outcome = true
15
+ end
16
+ end
17
+ 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.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
- - vaughanbrittonsage
7
+ - SageOne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-13 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,7 +69,7 @@ dependencies:
69
69
  description: A Validation framework for creating validation profiles, allowing for
70
70
  the separation & reuse of validation logic from the object being validated.
71
71
  email:
72
- - vaughanbritton@gmail.com
72
+ - vaughan.britton@sage.com
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
@@ -77,6 +77,7 @@ files:
77
77
  - bin/console
78
78
  - bin/setup
79
79
  - lib/validation_profiler.rb
80
+ - lib/validation_profiler/class_methods.rb
80
81
  - lib/validation_profiler/exceptions.rb
81
82
  - lib/validation_profiler/exceptions/field_not_found.rb
82
83
  - lib/validation_profiler/exceptions/invalid_field_type.rb
@@ -84,6 +85,8 @@ files:
84
85
  - lib/validation_profiler/exceptions/invalid_validation_rule_type.rb
85
86
  - lib/validation_profiler/exceptions/validation_rule_already_exists.rb
86
87
  - lib/validation_profiler/exceptions/validation_rule_not_found.rb
88
+ - lib/validation_profiler/manager.rb
89
+ - lib/validation_profiler/manager_result.rb
87
90
  - lib/validation_profiler/rules.rb
88
91
  - lib/validation_profiler/rules/child_validation_rule.rb
89
92
  - lib/validation_profiler/rules/condition_validation_rule.rb
@@ -103,7 +106,6 @@ files:
103
106
  - lib/validation_profiler/rules/time_validation_rule.rb
104
107
  - lib/validation_profiler/rules/validation_rule.rb
105
108
  - lib/validation_profiler/rules/validation_rule_manager.rb
106
- - lib/validation_profiler/version.rb
107
109
  homepage: https://github.com/vaughanbrittonsage/validation_profiler
108
110
  licenses:
109
111
  - MIT
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  version: '0'
125
127
  requirements: []
126
128
  rubyforge_project:
127
- rubygems_version: 2.5.1
129
+ rubygems_version: 2.4.5
128
130
  signing_key:
129
131
  specification_version: 4
130
132
  summary: A Validation framework for creating validation profiles, allowing for the
@@ -1,3 +0,0 @@
1
- module ValidationProfiler
2
- VERSION = "1.3.1"
3
- end