evt-validate 0.3.1.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5068329b01d123d8c26e474ef4da83200f435e53
4
+ data.tar.gz: 92ee974a1e65c0724d4ff4cf07c8531e0cd9b899
5
+ SHA512:
6
+ metadata.gz: f80363300b885a6d778627d677921a7647ccd41eddceb9fa6771b28d1a78dc1550126670c7e4d484b56eaf08cadf5d13e0bed6fd6017b410d021e18ecc33f4f1
7
+ data.tar.gz: 147fb88627c7d4a3017330aff0fab0ecc8b924200ec9a560b94efe21104ae80631c9e8f697b049a9dd5378d4361148243f3d97c796f819418c20ada46d48703c
@@ -0,0 +1,18 @@
1
+ module Validate
2
+ module Controls
3
+ module NoScenarioAccessor
4
+ class Example
5
+ module Validator
6
+ end
7
+ end
8
+
9
+ def self.example
10
+ Example.new
11
+ end
12
+
13
+ def self.example_class
14
+ Example
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Validate
2
+ module Controls
3
+ module NoValidator
4
+ class Example
5
+ end
6
+
7
+ def self.example
8
+ Example.new
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Validate
2
+ module Controls
3
+ module Validator
4
+ module Default
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validator
11
+ def self.call(subject)
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Validate
2
+ module Controls
3
+ module Validator
4
+ module NotBooleanResult
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validator
11
+ def self.call(subject)
12
+ :something
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Validate
2
+ module Controls
3
+ module Validator
4
+ module Scenario
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validator
11
+ def self.some_scenario
12
+ SomeScenario
13
+ end
14
+
15
+ module SomeScenario
16
+ def self.call(subject)
17
+ true
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module Validate
2
+ module Controls
3
+ module Validator
4
+ module Scenarios
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validator
11
+ def self.some_scenario
12
+ SomeScenario
13
+ end
14
+
15
+ def self.some_other_scenario
16
+ SomeOtherScenario
17
+ end
18
+
19
+ module SomeScenario
20
+ def self.call(subject, state)
21
+ state << :some_scenario
22
+ false
23
+ end
24
+ end
25
+
26
+ module SomeOtherScenario
27
+ def self.call(subject, state)
28
+ state << :some_other_scenario
29
+ true
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ module Validate
2
+ module Controls
3
+ module Validator
4
+ module State
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validator
11
+ def self.call(subject, state)
12
+ state << :some_entry
13
+ true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ require 'validate/controls/validator/default'
2
+ require 'validate/controls/validator/state'
3
+ require 'validate/controls/validator/not_boolean_result'
4
+ require 'validate/controls/validator/scenario'
5
+ require 'validate/controls/validator/scenarios'
6
+ require 'validate/controls/no_validator'
7
+ require 'validate/controls/no_scenario_accessor'
@@ -0,0 +1,96 @@
1
+ module Validate
2
+ extend self
3
+
4
+ class Error < RuntimeError; end
5
+
6
+ def call(subject, state=nil, scenario: nil, scenarios: nil)
7
+ validator = validator(subject)
8
+
9
+ if scenarios.nil?
10
+ scenarios = scenario
11
+ end
12
+ scenarios = Array(scenarios)
13
+
14
+ if scenarios.empty?
15
+ validate(validator, subject, state)
16
+ else
17
+ validate_scenarios(validator, subject, state, scenarios)
18
+ end
19
+ end
20
+
21
+ def validate_scenarios(validator, subject, state, scenarios)
22
+ result = true
23
+ scenarios.each do |scenario|
24
+ scenario_validator = scenario(validator, scenario)
25
+ result = result & validate(scenario_validator, subject, state)
26
+ end
27
+
28
+ result
29
+ end
30
+
31
+ def validate(validator, subject, state)
32
+ method = validator.method(:call)
33
+
34
+ result = nil
35
+ case method.parameters.length
36
+ when 1
37
+ if !state.nil?
38
+ raise Error, "State argument was supplied but the validator does not provide a state parameter (Validator: #{validator})"
39
+ end
40
+
41
+ result = validator.public_send :call, subject
42
+ when 2
43
+ result = validator.public_send :call, subject, state
44
+ end
45
+
46
+ unless result.is_a?(TrueClass) || result.is_a?(FalseClass)
47
+ raise Error, "Result must be boolean. The result is a #{result.class}. (Validator: #{validator})"
48
+ end
49
+
50
+ result
51
+ end
52
+
53
+ def validator(subject)
54
+ subject_const = subject_const(subject)
55
+
56
+ assure_validator(subject_const)
57
+ get_validator(subject_const)
58
+ end
59
+
60
+ def subject_const(subject)
61
+ [Module, Class].include?(subject.class) ? subject : subject.class
62
+ end
63
+
64
+ def assure_validator(subject_const)
65
+ unless validator_const?(subject_const)
66
+ raise Error, "#{subject_const.name} doesn't have a `Validator' namespace"
67
+ end
68
+ end
69
+
70
+ def validator_const?(subject_const)
71
+ subject_const.const_defined?(:Validator)
72
+ end
73
+
74
+ def get_validator(subject_const)
75
+ subject_const.const_get(:Validator)
76
+ end
77
+
78
+ def scenario(validator, scenario)
79
+ assure_scenario(validator, scenario)
80
+ get_scenario(validator, scenario)
81
+ end
82
+
83
+ def assure_scenario(validator, scenario)
84
+ unless scenario_method?(validator, scenario)
85
+ raise Error, "#{validator.name} doesn't have a `#{scenario}' scenario method"
86
+ end
87
+ end
88
+
89
+ def scenario_method?(validator, scenario)
90
+ validator.respond_to?(scenario)
91
+ end
92
+
93
+ def get_scenario(validator, scenario)
94
+ validator.public_send(scenario)
95
+ end
96
+ end
data/lib/validate.rb ADDED
@@ -0,0 +1 @@
1
+ require 'validate/validate'
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-validate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1.3
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ntl-test_bench
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: " "
28
+ email: opensource@eventide-project.org
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/validate.rb
34
+ - lib/validate/controls.rb
35
+ - lib/validate/controls/no_scenario_accessor.rb
36
+ - lib/validate/controls/no_validator.rb
37
+ - lib/validate/controls/validator/default.rb
38
+ - lib/validate/controls/validator/not_boolean_result.rb
39
+ - lib/validate/controls/validator/scenario.rb
40
+ - lib/validate/controls/validator/scenarios.rb
41
+ - lib/validate/controls/validator/state.rb
42
+ - lib/validate/validate.rb
43
+ homepage: https://github.com/eventide-project/validate
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.3
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.5.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Interface and protocol for validating and validation discovery
67
+ test_files: []