evt-validate 0.3.1.5 → 0.4.0.0

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
- SHA1:
3
- metadata.gz: e3e1a1fde821b71c368e1e4242b2f47b12d7a946
4
- data.tar.gz: 77cf00ea476c194c064b3812d752045e95248755
2
+ SHA256:
3
+ metadata.gz: c4007f5c5b6c47b27fb02f00385666d2dbb8e4a7c94462df15b3dc9c962e721a
4
+ data.tar.gz: c33abd287c42e13184c3bcce29be9be0435a6bef70331518739706d13a0561e8
5
5
  SHA512:
6
- metadata.gz: 2516f350c561ce3cc7aa99e10670ae7b952f57c50ea94ff135ebe72c292d7b072813c319aee531ca9b06728d757dfb2f72bad5c8d7f1a442fa791277991cb0c9
7
- data.tar.gz: d5ecde2e546e169c6e797701a6fa6b4748163e7a96e4021cc69f8fcd6bf1497fd5994232b695ed8c97e83a4eb2e5e70b12b95b0d970ec6b58217298936ce5e89
6
+ metadata.gz: fa2d75dca4d0c483cd400dd39c12ea6b610dccb03f727cfc820594759588e0bc32270169405ba7b8efa3c64b14d725b545e490a1702b6ef7e0af0b4f8a438efc
7
+ data.tar.gz: 567fabcb67cd490de52377cd73a5b4893b20249bb5f450e5eec2fcd1b2d7c3a594a5f68aad311364bd4f0b3a6b5a054c77bb7e73a70e4236c04c8d821d7df93f
data/lib/validate.rb CHANGED
@@ -1 +1,3 @@
1
+ require 'reflect'
2
+
1
3
  require 'validate/validate'
@@ -1,3 +1,5 @@
1
+ require 'validate/controls/validate/default'
2
+ require 'validate/controls/validate/scenarios'
1
3
  require 'validate/controls/validator/default'
2
4
  require 'validate/controls/validator/state'
3
5
  require 'validate/controls/validator/not_boolean_result'
@@ -0,0 +1,19 @@
1
+ module Validate
2
+ module Controls
3
+ module Validate
4
+ module Default
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validate
11
+ def self.call(subject)
12
+ true
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ module Validate
2
+ module Controls
3
+ module Validate
4
+ module Scenarios
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ module Validate
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
@@ -1,28 +1,66 @@
1
1
  module Validate
2
2
  extend self
3
3
 
4
- class Error < RuntimeError; end
4
+ Error = Class.new(RuntimeError)
5
5
 
6
6
  def call(subject, state=nil, scenario: nil, scenarios: nil)
7
- validator = validator(subject)
8
-
9
7
  if scenarios.nil?
10
8
  scenarios = scenario
11
9
  end
12
- scenarios = Array(scenarios)
10
+ scenario_names = Array(scenarios)
11
+
12
+ validator_reflection = validator_reflection(subject)
13
13
 
14
- if scenarios.empty?
15
- validate(validator, subject, state)
14
+ if scenario_names.empty?
15
+ validator = validator_reflection.constant
16
+ validate(validator_reflection.constant, subject, state)
16
17
  else
17
- validate_scenarios(validator, subject, state, scenarios)
18
+ validate_scenarios(validator_reflection, subject, state, scenario_names)
18
19
  end
19
20
  end
20
21
 
21
- def validate_scenarios(validator, subject, state, scenarios)
22
+ def validator_reflection(subject)
23
+ subject_constant = Reflect.subject_constant(subject)
24
+
25
+ validator_name = validator_name(subject_constant)
26
+
27
+ if validator_name.nil?
28
+ raise Error, "#{subject_constant.name} doesn't have a Validate or Validator namespace"
29
+ end
30
+
31
+ Reflect.(subject, validator_name, strict: true)
32
+ end
33
+
34
+ def validator_name(subject_constant)
35
+ if validate_const?(subject_constant)
36
+ return :Validate
37
+ elsif validator_const?(subject_constant)
38
+ return :Validator
39
+ else
40
+ return nil
41
+ end
42
+ end
43
+
44
+ def validate_const?(subject_constant)
45
+ Reflect.constant?(subject_constant, :Validate)
46
+ end
47
+
48
+ def validator_const?(subject_constant)
49
+ Reflect.constant?(subject_constant, :Validator)
50
+ end
51
+
52
+ def validate_scenarios(validator_reflection, subject, state, scenario_names)
22
53
  result = true
23
- scenarios.each do |scenario|
24
- scenario_validator = scenario(validator, scenario)
25
- result = result & validate(scenario_validator, subject, state)
54
+ scenario_names.each do |scenario_name|
55
+ scenario_reflection = validator_reflection.get(scenario_name, strict: false)
56
+
57
+ if scenario_reflection.nil?
58
+ raise Error, "#{validator_reflection.constant.name} doesn't have a `#{scenario_name}' scenario accessor"
59
+ end
60
+
61
+ validator = scenario_reflection.constant
62
+
63
+ result = result & validate(validator, subject, state)
26
64
  end
27
65
 
28
66
  result
@@ -49,48 +87,4 @@ module Validate
49
87
 
50
88
  result
51
89
  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
90
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-validate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1.5
4
+ version: 0.4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-01 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: evt-reflect
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: test_bench
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -34,6 +48,8 @@ files:
34
48
  - lib/validate/controls.rb
35
49
  - lib/validate/controls/no_scenario_accessor.rb
36
50
  - lib/validate/controls/no_validator.rb
51
+ - lib/validate/controls/validate/default.rb
52
+ - lib/validate/controls/validate/scenarios.rb
37
53
  - lib/validate/controls/validator/default.rb
38
54
  - lib/validate/controls/validator/not_boolean_result.rb
39
55
  - lib/validate/controls/validator/scenario.rb
@@ -60,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
76
  version: '0'
61
77
  requirements: []
62
78
  rubyforge_project:
63
- rubygems_version: 2.6.11
79
+ rubygems_version: 2.7.3
64
80
  signing_key:
65
81
  specification_version: 4
66
82
  summary: Interface and protocol for validating and validation discovery