substation 0.0.8 → 0.0.9

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.
Files changed (85) hide show
  1. data/.travis.yml +4 -0
  2. data/Changelog.md +92 -2
  3. data/Gemfile.devtools +19 -17
  4. data/README.md +116 -46
  5. data/config/flay.yml +2 -2
  6. data/config/mutant.yml +1 -0
  7. data/config/reek.yml +11 -5
  8. data/config/rubocop.yml +35 -0
  9. data/lib/substation.rb +10 -1
  10. data/lib/substation/chain.rb +108 -64
  11. data/lib/substation/chain/dsl.rb +62 -37
  12. data/lib/substation/dispatcher.rb +3 -1
  13. data/lib/substation/environment.rb +9 -6
  14. data/lib/substation/environment/dsl.rb +4 -3
  15. data/lib/substation/observer.rb +2 -0
  16. data/lib/substation/processor.rb +106 -7
  17. data/lib/substation/processor/evaluator.rb +98 -7
  18. data/lib/substation/processor/transformer.rb +26 -0
  19. data/lib/substation/processor/wrapper.rb +5 -3
  20. data/lib/substation/request.rb +12 -1
  21. data/lib/substation/response.rb +13 -0
  22. data/lib/substation/utils.rb +3 -1
  23. data/lib/substation/version.rb +3 -1
  24. data/spec/integration/substation/dispatcher/call_spec.rb +12 -12
  25. data/spec/spec_helper.rb +39 -32
  26. data/spec/unit/substation/chain/call_spec.rb +205 -29
  27. data/spec/unit/substation/chain/class_methods/failure_response_spec.rb +16 -0
  28. data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +7 -4
  29. data/spec/unit/substation/chain/dsl/class_methods/build_spec.rb +24 -0
  30. data/spec/unit/substation/chain/dsl/failure_chain_spec.rb +35 -0
  31. data/spec/unit/substation/chain/dsl/processors_spec.rb +8 -6
  32. data/spec/unit/substation/chain/dsl/use_spec.rb +1 -1
  33. data/spec/unit/substation/chain/each_spec.rb +5 -9
  34. data/spec/unit/substation/chain/failure_data/equalizer_spec.rb +46 -0
  35. data/spec/unit/substation/chain/failure_data/hash_spec.rb +13 -0
  36. data/spec/unit/substation/dispatcher/action/call_spec.rb +2 -1
  37. data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +7 -5
  38. data/spec/unit/substation/dispatcher/call_spec.rb +2 -2
  39. data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +6 -6
  40. data/spec/unit/substation/environment/chain_spec.rb +22 -27
  41. data/spec/unit/substation/environment/class_methods/build_spec.rb +11 -4
  42. data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +5 -3
  43. data/spec/unit/substation/environment/dsl/register_spec.rb +8 -3
  44. data/spec/unit/substation/environment/dsl/registry_spec.rb +5 -3
  45. data/spec/unit/substation/environment/equalizer_spec.rb +25 -0
  46. data/spec/unit/substation/observer/chain/call_spec.rb +2 -0
  47. data/spec/unit/substation/observer/class_methods/coerce_spec.rb +2 -0
  48. data/spec/unit/substation/observer/null/call_spec.rb +2 -0
  49. data/spec/unit/substation/processor/evaluator/call_spec.rb +20 -10
  50. data/spec/unit/substation/processor/evaluator/class_methods/new_spec.rb +9 -0
  51. data/spec/unit/substation/processor/evaluator/data/call_spec.rb +34 -0
  52. data/spec/unit/substation/processor/evaluator/pivot/call_spec.rb +34 -0
  53. data/spec/unit/substation/processor/evaluator/request/call_spec.rb +34 -0
  54. data/spec/unit/substation/processor/fallible/name_spec.rb +15 -0
  55. data/spec/unit/substation/processor/fallible/with_failure_chain_spec.rb +18 -0
  56. data/spec/unit/substation/processor/incoming/result_spec.rb +25 -0
  57. data/spec/unit/substation/processor/outgoing/call_spec.rb +28 -0
  58. data/spec/unit/substation/processor/outgoing/name_spec.rb +14 -0
  59. data/spec/unit/substation/processor/outgoing/success_predicate_spec.rb +15 -0
  60. data/spec/unit/substation/{chain/outgoing → processor}/result_spec.rb +4 -3
  61. data/spec/unit/substation/processor/success_predicate_spec.rb +22 -0
  62. data/spec/unit/substation/processor/transformer/call_spec.rb +21 -0
  63. data/spec/unit/substation/processor/wrapper/call_spec.rb +9 -7
  64. data/spec/unit/substation/request/env_spec.rb +3 -2
  65. data/spec/unit/substation/request/error_spec.rb +2 -1
  66. data/spec/unit/substation/request/input_spec.rb +3 -2
  67. data/spec/unit/substation/request/name_spec.rb +15 -0
  68. data/spec/unit/substation/request/success_spec.rb +2 -1
  69. data/spec/unit/substation/response/env_spec.rb +3 -2
  70. data/spec/unit/substation/response/failure/success_predicate_spec.rb +2 -1
  71. data/spec/unit/substation/response/input_spec.rb +3 -2
  72. data/spec/unit/substation/response/output_spec.rb +2 -1
  73. data/spec/unit/substation/response/request_spec.rb +3 -2
  74. data/spec/unit/substation/response/success/success_predicate_spec.rb +2 -1
  75. data/spec/unit/substation/response/to_request_spec.rb +19 -0
  76. data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +14 -12
  77. data/spec/unit/substation/utils/class_methods/const_get_spec.rb +6 -6
  78. data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +4 -4
  79. metadata +25 -9
  80. data/lib/substation/processor/pivot.rb +0 -25
  81. data/spec/unit/substation/chain/class_methods/build_spec.rb +0 -31
  82. data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +0 -23
  83. data/spec/unit/substation/chain/incoming/result_spec.rb +0 -21
  84. data/spec/unit/substation/chain/outgoing/call_spec.rb +0 -25
  85. data/spec/unit/substation/processor/pivot/call_spec.rb +0 -16
@@ -6,9 +6,10 @@ describe Request, '#env' do
6
6
 
7
7
  subject { object.env }
8
8
 
9
- let(:object) { described_class.new(env, input) }
9
+ let(:object) { described_class.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
 
13
- it { should equal(env) }
14
+ it { should be(env) }
14
15
  end
@@ -6,7 +6,8 @@ describe Request, '#error' do
6
6
 
7
7
  subject { object.error(output) }
8
8
 
9
- let(:object) { described_class.new(env, input) }
9
+ let(:object) { described_class.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
  let(:output) { mock }
@@ -6,9 +6,10 @@ describe Request, '#input' do
6
6
 
7
7
  subject { object.input }
8
8
 
9
- let(:object) { described_class.new(env, input) }
9
+ let(:object) { described_class.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
 
13
- it { should equal(input) }
14
+ it { should be(input) }
14
15
  end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Request, '#name' do
6
+
7
+ subject { object.name }
8
+
9
+ let(:object) { described_class.new(name, env, input) }
10
+ let(:name) { mock }
11
+ let(:env) { mock }
12
+ let(:input) { mock }
13
+
14
+ it { should be(name) }
15
+ end
@@ -6,7 +6,8 @@ describe Request, '#success' do
6
6
 
7
7
  subject { object.success(output) }
8
8
 
9
- let(:object) { described_class.new(env, input) }
9
+ let(:object) { described_class.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
  let(:output) { mock }
@@ -7,10 +7,11 @@ describe Response, '#env' do
7
7
  subject { object.env }
8
8
 
9
9
  let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
10
+ let(:request) { Request.new(name, env, input) }
11
+ let(:name) { mock }
11
12
  let(:env) { mock }
12
13
  let(:input) { mock }
13
14
  let(:output) { mock }
14
15
 
15
- it { should equal(env) }
16
+ it { should be(env) }
16
17
  end
@@ -6,7 +6,8 @@ describe Response::Failure, '#success?' do
6
6
  subject { object.success? }
7
7
 
8
8
  let(:object) { described_class.new(request, output) }
9
- let(:request) { Request.new(env, input) }
9
+ let(:request) { Request.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
  let(:output) { mock }
@@ -7,10 +7,11 @@ describe Response, '#input' do
7
7
  subject { object.input }
8
8
 
9
9
  let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
10
+ let(:request) { Request.new(name, env, input) }
11
+ let(:name) { mock }
11
12
  let(:env) { mock }
12
13
  let(:input) { mock }
13
14
  let(:output) { mock }
14
15
 
15
- it { should equal(input) }
16
+ it { should be(input) }
16
17
  end
@@ -7,7 +7,8 @@ describe Response, '#output' do
7
7
  subject { object.output }
8
8
 
9
9
  let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
10
+ let(:request) { Request.new(name, env, input) }
11
+ let(:name) { mock }
11
12
  let(:env) { mock }
12
13
  let(:input) { mock }
13
14
  let(:output) { mock }
@@ -7,10 +7,11 @@ describe Response, '#request' do
7
7
  subject { object.request }
8
8
 
9
9
  let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
10
+ let(:request) { Request.new(name, env, input) }
11
+ let(:name) { mock }
11
12
  let(:env) { mock }
12
13
  let(:input) { mock }
13
14
  let(:output) { mock }
14
15
 
15
- it { should equal(request) }
16
+ it { should be(request) }
16
17
  end
@@ -6,7 +6,8 @@ describe Response::Success, '#success?' do
6
6
  subject { object.success? }
7
7
 
8
8
  let(:object) { described_class.new(request, output) }
9
- let(:request) { Request.new(env, input) }
9
+ let(:request) { Request.new(name, env, input) }
10
+ let(:name) { mock }
10
11
  let(:env) { mock }
11
12
  let(:input) { mock }
12
13
  let(:output) { mock }
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Response, '#to_request' do
6
+
7
+ subject { object.to_request }
8
+
9
+ let(:object) { Class.new(described_class).new(request, output) }
10
+ let(:request) { Request.new(name, env, input) }
11
+ let(:name) { mock }
12
+ let(:env) { mock }
13
+ let(:input) { mock }
14
+ let(:output) { mock }
15
+
16
+ let(:response) { Request.new(name, env, output) }
17
+
18
+ it { should eql(response) }
19
+ end
@@ -6,37 +6,39 @@ describe Utils, '.coerce_callable' do
6
6
 
7
7
  subject { described_class.coerce_callable(handler) }
8
8
 
9
- context "with a String handler" do
10
- let(:handler) { 'Spec::Action::Success' }
9
+ let(:const) { Spec::Action::Success }
10
+
11
+ context 'with a String handler' do
12
+ let(:handler) { const.name }
11
13
 
12
14
  it { should be(Spec::Action::Success) }
13
15
  end
14
16
 
15
- context "with a Symbol handler" do
16
- let(:handler) { :'Spec::Action::Success' }
17
+ context 'with a Symbol handler' do
18
+ let(:handler) { const.name.to_sym }
17
19
 
18
20
  it { should be(Spec::Action::Success) }
19
21
  end
20
22
 
21
- context "with a const handler" do
22
- let(:handler) { Spec::Action::Success }
23
+ context 'with a const handler' do
24
+ let(:handler) { const }
23
25
 
24
- it { should be(Spec::Action::Success) }
26
+ it { should be(const) }
25
27
  end
26
28
 
27
- context "with a Proc handler" do
28
- let(:handler) { Proc.new { |response| respone } }
29
+ context 'with a Proc handler' do
30
+ let(:handler) { ->(response) { response } }
29
31
 
30
32
  it { should be(handler) }
31
33
  end
32
34
 
33
- context "with a Chain handler" do
34
- let(:handler) { Chain.new([]) }
35
+ context 'with a Chain handler' do
36
+ let(:handler) { Chain.new(EMPTY_ARRAY, Chain::EMPTY) }
35
37
 
36
38
  it { should be(handler) }
37
39
  end
38
40
 
39
- context "with an unsupported handler" do
41
+ context 'with an unsupported handler' do
40
42
  let(:handler) { mock }
41
43
 
42
44
  specify do
@@ -6,33 +6,33 @@ describe Utils, '.const_get' do
6
6
 
7
7
  subject { described_class.const_get(name) }
8
8
 
9
- context "with a toplevel constant" do
10
- context "given as String" do
9
+ context 'with a toplevel constant' do
10
+ context 'given as String' do
11
11
  let(:name) { 'Substation' }
12
12
 
13
13
  it { should == Substation }
14
14
  end
15
15
 
16
- context "given as Symbol" do
16
+ context 'given as Symbol' do
17
17
  let(:name) { :Substation }
18
18
 
19
19
  it { should == Substation }
20
20
  end
21
21
  end
22
22
 
23
- context "with a FQN toplevel constant" do
23
+ context 'with a FQN toplevel constant' do
24
24
  let(:name) { '::Substation' }
25
25
 
26
26
  it { should == Substation }
27
27
  end
28
28
 
29
- context "with a nested constant" do
29
+ context 'with a nested constant' do
30
30
  let(:name) { 'Substation::Request' }
31
31
 
32
32
  it { should == Substation::Request }
33
33
  end
34
34
 
35
- context "with a non-existant nested constant" do
35
+ context 'with a non-existant nested constant' do
36
36
  let(:name) { 'Substation::Foo' }
37
37
 
38
38
  before do
@@ -6,15 +6,15 @@ describe Utils, '.symbolize_keys' do
6
6
 
7
7
  subject { described_class.symbolize_keys(hash) }
8
8
 
9
- context "with no nested hash" do
9
+ context 'with no nested hash' do
10
10
  let(:hash) { { 'foo' => 'bar' } }
11
11
 
12
- it { should == { :foo => 'bar'} }
12
+ it { should == { :foo => 'bar' } }
13
13
  end
14
14
 
15
- context "with a nested hash" do
15
+ context 'with a nested hash' do
16
16
  let(:hash) { { 'foo' => { 'bar' => 'baz' } } }
17
17
 
18
- it { should == { :foo => { :bar => 'baz'} } }
18
+ it { should == { :foo => { :bar => 'baz' } } }
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: substation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-19 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: adamantium
@@ -120,6 +120,7 @@ files:
120
120
  - config/flog.yml
121
121
  - config/mutant.yml
122
122
  - config/reek.yml
123
+ - config/rubocop.yml
123
124
  - config/yardstick.yml
124
125
  - lib/substation.rb
125
126
  - lib/substation/chain.rb
@@ -130,7 +131,7 @@ files:
130
131
  - lib/substation/observer.rb
131
132
  - lib/substation/processor.rb
132
133
  - lib/substation/processor/evaluator.rb
133
- - lib/substation/processor/pivot.rb
134
+ - lib/substation/processor/transformer.rb
134
135
  - lib/substation/processor/wrapper.rb
135
136
  - lib/substation/request.rb
136
137
  - lib/substation/response.rb
@@ -139,17 +140,17 @@ files:
139
140
  - spec/integration/substation/dispatcher/call_spec.rb
140
141
  - spec/spec_helper.rb
141
142
  - spec/unit/substation/chain/call_spec.rb
142
- - spec/unit/substation/chain/class_methods/build_spec.rb
143
+ - spec/unit/substation/chain/class_methods/failure_response_spec.rb
143
144
  - spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb
144
145
  - spec/unit/substation/chain/dsl/builder/dsl_spec.rb
145
146
  - spec/unit/substation/chain/dsl/chain_spec.rb
146
- - spec/unit/substation/chain/dsl/class_methods/processors_spec.rb
147
+ - spec/unit/substation/chain/dsl/class_methods/build_spec.rb
148
+ - spec/unit/substation/chain/dsl/failure_chain_spec.rb
147
149
  - spec/unit/substation/chain/dsl/processors_spec.rb
148
150
  - spec/unit/substation/chain/dsl/use_spec.rb
149
151
  - spec/unit/substation/chain/each_spec.rb
150
- - spec/unit/substation/chain/incoming/result_spec.rb
151
- - spec/unit/substation/chain/outgoing/call_spec.rb
152
- - spec/unit/substation/chain/outgoing/result_spec.rb
152
+ - spec/unit/substation/chain/failure_data/equalizer_spec.rb
153
+ - spec/unit/substation/chain/failure_data/hash_spec.rb
153
154
  - spec/unit/substation/dispatcher/action/call_spec.rb
154
155
  - spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb
155
156
  - spec/unit/substation/dispatcher/action_names_spec.rb
@@ -160,15 +161,29 @@ files:
160
161
  - spec/unit/substation/environment/dsl/class_methods/registry_spec.rb
161
162
  - spec/unit/substation/environment/dsl/register_spec.rb
162
163
  - spec/unit/substation/environment/dsl/registry_spec.rb
164
+ - spec/unit/substation/environment/equalizer_spec.rb
163
165
  - spec/unit/substation/observer/chain/call_spec.rb
164
166
  - spec/unit/substation/observer/class_methods/coerce_spec.rb
165
167
  - spec/unit/substation/observer/null/call_spec.rb
166
168
  - spec/unit/substation/processor/evaluator/call_spec.rb
167
- - spec/unit/substation/processor/pivot/call_spec.rb
169
+ - spec/unit/substation/processor/evaluator/class_methods/new_spec.rb
170
+ - spec/unit/substation/processor/evaluator/data/call_spec.rb
171
+ - spec/unit/substation/processor/evaluator/pivot/call_spec.rb
172
+ - spec/unit/substation/processor/evaluator/request/call_spec.rb
173
+ - spec/unit/substation/processor/fallible/name_spec.rb
174
+ - spec/unit/substation/processor/fallible/with_failure_chain_spec.rb
175
+ - spec/unit/substation/processor/incoming/result_spec.rb
176
+ - spec/unit/substation/processor/outgoing/call_spec.rb
177
+ - spec/unit/substation/processor/outgoing/name_spec.rb
178
+ - spec/unit/substation/processor/outgoing/success_predicate_spec.rb
179
+ - spec/unit/substation/processor/result_spec.rb
180
+ - spec/unit/substation/processor/success_predicate_spec.rb
181
+ - spec/unit/substation/processor/transformer/call_spec.rb
168
182
  - spec/unit/substation/processor/wrapper/call_spec.rb
169
183
  - spec/unit/substation/request/env_spec.rb
170
184
  - spec/unit/substation/request/error_spec.rb
171
185
  - spec/unit/substation/request/input_spec.rb
186
+ - spec/unit/substation/request/name_spec.rb
172
187
  - spec/unit/substation/request/success_spec.rb
173
188
  - spec/unit/substation/response/env_spec.rb
174
189
  - spec/unit/substation/response/failure/success_predicate_spec.rb
@@ -176,6 +191,7 @@ files:
176
191
  - spec/unit/substation/response/output_spec.rb
177
192
  - spec/unit/substation/response/request_spec.rb
178
193
  - spec/unit/substation/response/success/success_predicate_spec.rb
194
+ - spec/unit/substation/response/to_request_spec.rb
179
195
  - spec/unit/substation/utils/class_methods/coerce_callable_spec.rb
180
196
  - spec/unit/substation/utils/class_methods/const_get_spec.rb
181
197
  - spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb
@@ -1,25 +0,0 @@
1
- module Substation
2
- module Processor
3
-
4
- # A processor to invoke a chain's pivot handler
5
- class Pivot
6
-
7
- include Processor
8
- include Chain::Pivot
9
- include Concord.new(:handler)
10
-
11
- # Invoke a chain's pivot handler
12
- #
13
- # @param [Request] request
14
- # the request to process
15
- #
16
- # @return [Response]
17
- #
18
- # @api private
19
- def call(request)
20
- handler.call(request)
21
- end
22
-
23
- end # class Caller
24
- end # module Processor
25
- end # module Substation
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Chain, '.build' do
4
-
5
- context "when a block is given" do
6
- subject { described_class.build(dsl, other, &block) }
7
-
8
- let(:dsl) { Chain::DSL::Builder.call(registry) }
9
- let(:registry) { { :test => Spec::Processor } }
10
- let(:other) { [ processor ] }
11
- let(:processor) { Spec::FAKE_PROCESSOR }
12
- let(:block) { lambda { |_| test(Spec::FAKE_HANDLER) } }
13
-
14
- let(:expected) { Chain.new(dsl.processors(other, &block)) }
15
-
16
- it { should eql(expected) }
17
- end
18
-
19
- context "when no block is given" do
20
- subject { described_class.build(dsl, other) }
21
-
22
- let(:dsl) { Chain::DSL::Builder.call(registry) }
23
- let(:registry) { { :test => Spec::Processor } }
24
- let(:other) { [ processor ] }
25
- let(:processor) { Spec::FAKE_PROCESSOR }
26
-
27
- let(:expected) { Chain.new(dsl.processors(other)) }
28
-
29
- it { should eql(expected) }
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Chain::DSL, '.processors' do
6
-
7
- let(:chain) { Chain::EMPTY }
8
-
9
- context "and a block is given" do
10
- subject { described_class.processors(chain, &block) }
11
-
12
- let(:block) { lambda { |_| use(Spec::FAKE_PROCESSOR) } }
13
- let(:processor) { Spec::FAKE_PROCESSOR }
14
-
15
- it { should include(processor) }
16
- end
17
-
18
- context "and no block is given" do
19
- subject { described_class.processors(chain) }
20
-
21
- it { should be_empty }
22
- end
23
- end