helpstation 0.1.6 → 0.1.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf088730fd2285591c8b41df53c5e890a72414f8
|
4
|
+
data.tar.gz: 16a7aafb3ecf830ed25e46bb775b5705930b5abf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2855f45dde608809423171874cf3ffaa5fa458e74d223986b8107c7d987858b24ecf487b862de3f45bb7ed69b9b641ed863ad4c56775b112b3173e2a9a4ba6
|
7
|
+
data.tar.gz: ccba834688babf44ce05af0f989c532157a6277e135f02ca63a13249d702d505411a7a3d1051a7982b1d922b8343b506c3e0fd50435f64c123ceb188244adb1f
|
@@ -43,5 +43,41 @@ module Helpstation
|
|
43
43
|
input.merge(result.output)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
# Helps to run one chain or another depending on a request
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# success_chain = substation.chain do
|
51
|
+
# # success action
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# fallback_chain = substation.chain do
|
55
|
+
# # fallback action
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# process ConditionalProcessor[
|
59
|
+
# -> (request) { request.input.has_key?(:optional_key) },
|
60
|
+
# success_chain,
|
61
|
+
# fallback_chain
|
62
|
+
# ]
|
63
|
+
#
|
64
|
+
class ConditionalProcessor < Processor
|
65
|
+
def self.[](condition, success_chain, fallback_chain)
|
66
|
+
Proc.new do |request|
|
67
|
+
result =
|
68
|
+
if condition.call(request)
|
69
|
+
success_chain.call(request)
|
70
|
+
else
|
71
|
+
fallback_chain.call(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
if result.is_a?(Substation::Response)
|
75
|
+
result
|
76
|
+
else
|
77
|
+
request.success(result.input)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
46
82
|
end
|
47
83
|
end
|
data/lib/helpstation/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Helpstation::Processors::ConditionalProcessor do
|
4
|
+
subject(:process) { processor.call(request) }
|
5
|
+
|
6
|
+
let(:processor) { described_class[condition, success_chain, fallback_chain] }
|
7
|
+
|
8
|
+
let(:input) { {} }
|
9
|
+
let(:env) { {} }
|
10
|
+
let(:request) { Substation::Request.new(:request, env, input) }
|
11
|
+
let(:condition) { double }
|
12
|
+
let(:success_chain) { double }
|
13
|
+
let(:fallback_chain) { double }
|
14
|
+
|
15
|
+
context 'when condition is true' do
|
16
|
+
let(:condition) { ->(_response) { true } }
|
17
|
+
|
18
|
+
it 'calls success chain' do
|
19
|
+
expect(success_chain).to receive(:call).with(request).and_return(request)
|
20
|
+
process
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when condition is false' do
|
25
|
+
let(:condition) { ->(_response) { false } }
|
26
|
+
|
27
|
+
it 'calls fallback chain' do
|
28
|
+
expect(fallback_chain).to receive(:call).with(request).and_return(request)
|
29
|
+
process
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when underlying chain returns request' do
|
34
|
+
let(:condition) { ->(_response) { true } }
|
35
|
+
|
36
|
+
it 'wrap it in success response' do
|
37
|
+
expect(success_chain).to receive(:call).with(request).and_return(request)
|
38
|
+
expect(process).to eq(Substation::Response::Success.new(request, input))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when underlying chain returns failure' do
|
43
|
+
let(:condition) { ->(_response) { true } }
|
44
|
+
|
45
|
+
it 'returns failure response' do
|
46
|
+
failure = Substation::Response::Failure.new(request, input)
|
47
|
+
expect(success_chain).to receive(:call).with(request).and_return(failure)
|
48
|
+
expect(process).to eq(failure)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helpstation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Indrek Juhkam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: substation
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- spec/helpstation/evaluator_spec.rb
|
75
75
|
- spec/helpstation/fetchers/active_record_fetcher_spec.rb
|
76
76
|
- spec/helpstation/fetchers/by_key_fetcher_spec.rb
|
77
|
+
- spec/helpstation/processors/conditional_processor_spec.rb
|
77
78
|
- spec/helpstation/processors/parallel_processor_spec.rb
|
78
79
|
- spec/spec_helper.rb
|
79
80
|
homepage: ''
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
version: '0'
|
97
98
|
requirements: []
|
98
99
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.6.7
|
100
101
|
signing_key:
|
101
102
|
specification_version: 4
|
102
103
|
summary: ''
|
@@ -104,5 +105,6 @@ test_files:
|
|
104
105
|
- spec/helpstation/evaluator_spec.rb
|
105
106
|
- spec/helpstation/fetchers/active_record_fetcher_spec.rb
|
106
107
|
- spec/helpstation/fetchers/by_key_fetcher_spec.rb
|
108
|
+
- spec/helpstation/processors/conditional_processor_spec.rb
|
107
109
|
- spec/helpstation/processors/parallel_processor_spec.rb
|
108
110
|
- spec/spec_helper.rb
|