substation 0.0.10.beta2 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.travis.yml +7 -3
  2. data/Changelog.md +99 -24
  3. data/Gemfile +8 -1
  4. data/Gemfile.devtools +37 -21
  5. data/Guardfile +1 -1
  6. data/README.md +118 -46
  7. data/TODO.md +1 -0
  8. data/config/flay.yml +2 -2
  9. data/config/flog.yml +1 -1
  10. data/config/reek.yml +41 -16
  11. data/config/rubocop.yml +44 -0
  12. data/config/yardstick.yml +1 -1
  13. data/lib/substation.rb +41 -5
  14. data/lib/substation/chain.rb +73 -84
  15. data/lib/substation/chain/definition.rb +147 -0
  16. data/lib/substation/chain/dsl.rb +150 -112
  17. data/lib/substation/chain/dsl/config.rb +55 -0
  18. data/lib/substation/chain/dsl/module_builder.rb +84 -0
  19. data/lib/substation/dispatcher.rb +20 -229
  20. data/lib/substation/dsl/guard.rb +96 -0
  21. data/lib/substation/dsl/registry.rb +181 -0
  22. data/lib/substation/environment.rb +126 -23
  23. data/lib/substation/environment/dsl.rb +31 -12
  24. data/lib/substation/processor.rb +238 -7
  25. data/lib/substation/processor/builder.rb +26 -0
  26. data/lib/substation/processor/config.rb +24 -0
  27. data/lib/substation/processor/evaluator.rb +66 -42
  28. data/lib/substation/processor/evaluator/handler.rb +54 -0
  29. data/lib/substation/processor/evaluator/result.rb +24 -0
  30. data/lib/substation/processor/executor.rb +46 -0
  31. data/lib/substation/processor/nest.rb +40 -0
  32. data/lib/substation/processor/transformer.rb +46 -0
  33. data/lib/substation/processor/wrapper.rb +16 -5
  34. data/lib/substation/request.rb +29 -27
  35. data/lib/substation/response.rb +19 -34
  36. data/lib/substation/response/api.rb +37 -0
  37. data/lib/substation/response/exception.rb +20 -0
  38. data/lib/substation/response/exception/output.rb +59 -0
  39. data/lib/substation/response/failure.rb +11 -0
  40. data/lib/substation/response/success.rb +11 -0
  41. data/lib/substation/version.rb +3 -1
  42. data/spec/demo/core.rb +64 -0
  43. data/spec/demo/core/action.rb +49 -0
  44. data/spec/demo/core/action/create_person.rb +28 -0
  45. data/spec/demo/core/errors.rb +16 -0
  46. data/spec/demo/core/facade.rb +38 -0
  47. data/spec/demo/core/handler.rb +21 -0
  48. data/spec/demo/core/handler/acceptor.rb +47 -0
  49. data/spec/demo/core/handler/authenticator.rb +36 -0
  50. data/spec/demo/core/handler/authorizer.rb +38 -0
  51. data/spec/demo/core/input.rb +15 -0
  52. data/spec/demo/core/observers.rb +10 -0
  53. data/spec/demo/core/validator.rb +21 -0
  54. data/spec/demo/domain/actor.rb +29 -0
  55. data/spec/demo/domain/dto/person.rb +18 -0
  56. data/spec/demo/domain/environment.rb +55 -0
  57. data/spec/demo/domain/storage.rb +49 -0
  58. data/spec/demo/web.rb +26 -0
  59. data/spec/demo/web/errors.rb +9 -0
  60. data/spec/demo/web/facade.rb +60 -0
  61. data/spec/demo/web/handler/deserializer.rb +36 -0
  62. data/spec/demo/web/presenter.rb +38 -0
  63. data/spec/demo/web/presenter/person.rb +19 -0
  64. data/spec/demo/web/renderer.rb +45 -0
  65. data/spec/demo/web/sanitizer.rb +35 -0
  66. data/spec/demo/web/sanitizer/person.rb +20 -0
  67. data/spec/demo/web/views.rb +28 -0
  68. data/spec/integration/demo/core_spec.rb +97 -0
  69. data/spec/integration/demo/web_spec.rb +114 -0
  70. data/spec/shared/context/integration/demo.rb +33 -0
  71. data/spec/shared/context/unit/chain.rb +13 -0
  72. data/spec/shared/context/unit/processor.rb +58 -0
  73. data/spec/shared/context/unit/request.rb +8 -0
  74. data/spec/shared/examples/integration/demo.rb +35 -0
  75. data/spec/shared/examples/unit/processor.rb +72 -0
  76. data/spec/spec_helper.rb +52 -23
  77. data/spec/unit/substation/chain/definition_spec.rb +141 -0
  78. data/spec/unit/substation/chain/dsl/config/dsl_module_spec.rb +13 -0
  79. data/spec/unit/substation/chain/dsl/config/registry_spec.rb +13 -0
  80. data/spec/unit/substation/chain/dsl/config_spec.rb +18 -0
  81. data/spec/unit/substation/chain/dsl/module_builder_spec.rb +77 -0
  82. data/spec/unit/substation/chain/dsl_spec.rb +175 -0
  83. data/spec/unit/substation/chain_spec.rb +303 -0
  84. data/spec/unit/substation/dispatcher_spec.rb +68 -0
  85. data/spec/unit/substation/dsl/guard_spec.rb +72 -0
  86. data/spec/unit/substation/dsl/registry_spec.rb +181 -0
  87. data/spec/unit/substation/environment/dsl_spec.rb +156 -0
  88. data/spec/unit/substation/environment_spec.rb +259 -0
  89. data/spec/unit/substation/processor/builder_spec.rb +21 -0
  90. data/spec/unit/substation/processor/config_spec.rb +40 -0
  91. data/spec/unit/substation/processor/evaluator/handler_spec.rb +20 -0
  92. data/spec/unit/substation/processor/evaluator/pivot_spec.rb +42 -0
  93. data/spec/unit/substation/processor/evaluator/request_spec.rb +11 -0
  94. data/spec/unit/substation/processor/evaluator/result/failure_spec.rb +14 -0
  95. data/spec/unit/substation/processor/evaluator/result/success_spec.rb +14 -0
  96. data/spec/unit/substation/processor/evaluator/result_spec.rb +13 -0
  97. data/spec/unit/substation/processor/evaluator_spec.rb +18 -0
  98. data/spec/unit/substation/processor/executor/null_spec.rb +25 -0
  99. data/spec/unit/substation/processor/executor_spec.rb +32 -0
  100. data/spec/unit/substation/processor/fallible_spec.rb +24 -0
  101. data/spec/unit/substation/processor/incoming_spec.rb +17 -0
  102. data/spec/unit/substation/processor/nest/incoming_spec.rb +56 -0
  103. data/spec/unit/substation/processor/nest_spec.rb +6 -0
  104. data/spec/unit/substation/processor/outgoing_spec.rb +47 -0
  105. data/spec/unit/substation/processor/transformer/incoming_spec.rb +17 -0
  106. data/spec/unit/substation/processor/transformer/outgoing_spec.rb +17 -0
  107. data/spec/unit/substation/processor/wrapper/incoming_spec.rb +15 -0
  108. data/spec/unit/substation/processor/wrapper/outgoing_spec.rb +15 -0
  109. data/spec/unit/substation/processor/wrapper_spec.rb +24 -0
  110. data/spec/unit/substation/processor_spec.rb +68 -0
  111. data/spec/unit/substation/request_spec.rb +70 -0
  112. data/spec/unit/substation/response/api_spec.rb +22 -0
  113. data/spec/unit/substation/response/exception/output_spec.rb +46 -0
  114. data/spec/unit/substation/response/exception_spec.rb +25 -0
  115. data/spec/unit/substation/response/failure_spec.rb +25 -0
  116. data/spec/unit/substation/response/success_spec.rb +24 -0
  117. data/spec/unit/substation/response_spec.rb +73 -0
  118. data/substation.gemspec +7 -6
  119. metadata +157 -67
  120. checksums.yaml +0 -7
  121. data/TODO +0 -0
  122. data/lib/substation/observer.rb +0 -66
  123. data/lib/substation/processor/pivot.rb +0 -25
  124. data/lib/substation/utils.rb +0 -68
  125. data/spec/integration/substation/dispatcher/call_spec.rb +0 -260
  126. data/spec/unit/substation/chain/call_spec.rb +0 -63
  127. data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +0 -19
  128. data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +0 -21
  129. data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +0 -30
  130. data/spec/unit/substation/chain/dsl/chain_spec.rb +0 -15
  131. data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +0 -24
  132. data/spec/unit/substation/chain/dsl/initialize_spec.rb +0 -19
  133. data/spec/unit/substation/chain/dsl/processors_spec.rb +0 -42
  134. data/spec/unit/substation/chain/dsl/use_spec.rb +0 -14
  135. data/spec/unit/substation/chain/each_spec.rb +0 -46
  136. data/spec/unit/substation/chain/incoming/result_spec.rb +0 -21
  137. data/spec/unit/substation/chain/outgoing/call_spec.rb +0 -25
  138. data/spec/unit/substation/chain/outgoing/result_spec.rb +0 -21
  139. data/spec/unit/substation/dispatcher/action/call_spec.rb +0 -23
  140. data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +0 -61
  141. data/spec/unit/substation/dispatcher/action_names_spec.rb +0 -14
  142. data/spec/unit/substation/dispatcher/call_spec.rb +0 -47
  143. data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +0 -20
  144. data/spec/unit/substation/environment/chain_spec.rb +0 -50
  145. data/spec/unit/substation/environment/class_methods/build_spec.rb +0 -11
  146. data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +0 -18
  147. data/spec/unit/substation/environment/dsl/register_spec.rb +0 -14
  148. data/spec/unit/substation/environment/dsl/registry_spec.rb +0 -19
  149. data/spec/unit/substation/observer/chain/call_spec.rb +0 -26
  150. data/spec/unit/substation/observer/class_methods/coerce_spec.rb +0 -33
  151. data/spec/unit/substation/observer/null/call_spec.rb +0 -12
  152. data/spec/unit/substation/processor/evaluator/call_spec.rb +0 -49
  153. data/spec/unit/substation/processor/pivot/call_spec.rb +0 -17
  154. data/spec/unit/substation/processor/wrapper/call_spec.rb +0 -20
  155. data/spec/unit/substation/request/env_spec.rb +0 -14
  156. data/spec/unit/substation/request/error_spec.rb +0 -15
  157. data/spec/unit/substation/request/input_spec.rb +0 -14
  158. data/spec/unit/substation/request/success_spec.rb +0 -15
  159. data/spec/unit/substation/response/env_spec.rb +0 -16
  160. data/spec/unit/substation/response/failure/success_predicate_spec.rb +0 -15
  161. data/spec/unit/substation/response/input_spec.rb +0 -16
  162. data/spec/unit/substation/response/output_spec.rb +0 -16
  163. data/spec/unit/substation/response/request_spec.rb +0 -16
  164. data/spec/unit/substation/response/success/success_predicate_spec.rb +0 -15
  165. data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +0 -46
  166. data/spec/unit/substation/utils/class_methods/const_get_spec.rb +0 -46
  167. data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +0 -20
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Dispatcher, '.coerce' do
6
-
7
- subject { described_class.coerce(config, env) }
8
-
9
- let(:config) {{
10
- 'test' => { 'action' => 'Spec::Action::Success' }
11
- }}
12
-
13
- let(:env) { double }
14
-
15
- let(:coerced) {{
16
- :test => described_class::Action.coerce(:action => 'Spec::Action::Success')
17
- }}
18
-
19
- it { should eql(described_class.new(coerced, env)) }
20
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Substation::Environment, '#chain' do
4
-
5
- let(:object) { described_class.build(&block) }
6
-
7
- let(:other) { Chain::EMPTY }
8
- let(:chain) { lambda { |_| test Spec::FAKE_HANDLER } }
9
- let(:dsl) { Chain::DSL::Builder.call(registry) }
10
- let(:registry) { described_class::DSL.registry(&block) }
11
- let(:block) { lambda { |_| register(:test, Spec::Processor) } }
12
-
13
- let(:expected) { Chain.new(processors) }
14
-
15
- context "when other is not given" do
16
- context "and a block is given" do
17
- subject { object.chain(&chain) }
18
-
19
- let(:processors) { dsl.processors(object, other, &chain) }
20
-
21
- it { should eql(expected) }
22
- end
23
-
24
- context "and no block is given" do
25
- subject { object.chain }
26
-
27
- let(:processors) { dsl.processors(object, other) }
28
-
29
- it { should eql(expected) }
30
- end
31
- end
32
-
33
- context "when other is given" do
34
- context "and a block is given" do
35
- subject { object.chain(other, &chain) }
36
-
37
- let(:processors) { dsl.processors(object, other, &chain) }
38
-
39
- it { should eql(expected) }
40
- end
41
-
42
- context "and no block is given" do
43
- subject { object.chain(other) }
44
-
45
- let(:processors) { dsl.processors(object, other) }
46
-
47
- it { should eql(expected) }
48
- end
49
- end
50
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Substation::Environment, '.build' do
4
- subject { described_class.build(&block) }
5
-
6
- let(:block) { lambda { |_| register(:test, Substation) } }
7
- let(:expected) { described_class.new(registry) }
8
- let(:registry) { described_class::DSL.registry(&block) }
9
-
10
- it { should eql(expected) }
11
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Substation::Environment::DSL, '.registry' do
4
- context "when a block is given" do
5
- subject { described_class.registry(&block) }
6
-
7
- let(:block) { lambda { |_| register :test, Spec::Processor } }
8
- let(:expected) { { :test => Spec::Processor } }
9
-
10
- it { should eql(expected) }
11
- end
12
-
13
- context "when no block is given" do
14
- subject { described_class.registry }
15
-
16
- it { should eql({}) }
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Substation::Environment::DSL, '#register' do
4
- subject { object.register(name, processor) }
5
-
6
- let(:object) { described_class.new }
7
- let(:name) { :test }
8
- let(:processor) { Spec::Processor }
9
-
10
- let(:expected) { { :test => Spec::Processor } }
11
- let(:block) { lambda { |_| register :test, Spec::Processor } }
12
-
13
- its(:registry) { should eql(expected) }
14
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Substation::Environment::DSL, '#registry' do
4
- subject { object.registry }
5
-
6
- context "when a block is given" do
7
- let(:object) { described_class.new(&block) }
8
- let(:block) { lambda { |_| register :test, Spec::Processor } }
9
- let(:expected) { { :test => Spec::Processor } }
10
-
11
- it { should eql(expected) }
12
- end
13
-
14
- context "when no block is given" do
15
- let(:object) { described_class.new }
16
-
17
- it { should eql({}) }
18
- end
19
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Observer::Chain, '#call' do
4
- subject { object.call(response) }
5
-
6
- let(:object) { Observer::Chain.new(observers) }
7
-
8
- let(:response) { double('Response') }
9
- let(:observer_a) { double('Observer A') }
10
- let(:observer_b) { double('Observer B') }
11
-
12
- let(:observers) { [observer_a, observer_b] }
13
-
14
- it_should_behave_like 'a command method'
15
-
16
- before do
17
- observer_a.stub(:call)
18
- observer_b.stub(:call)
19
- end
20
-
21
- it 'should call observers' do
22
- observer_a.should_receive(:call).with(response)
23
- observer_b.should_receive(:call).with(response)
24
- subject
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Observer, '.coerce' do
4
-
5
- subject { object.coerce(input) }
6
-
7
- let(:object) { described_class }
8
-
9
- context 'with nil input' do
10
- let(:input) { nil }
11
-
12
- it { should be(described_class::NULL) }
13
- end
14
-
15
- context 'with array input' do
16
- let(:input) { ['Spec::Observer', nil] }
17
-
18
- let(:observers) { [Spec::Observer, described_class::NULL] }
19
-
20
- it { should eql(described_class::Chain.new(observers)) }
21
- end
22
-
23
- context 'with other input' do
24
- let(:input) { double }
25
- let(:coerced) { double }
26
-
27
- before do
28
- Utils.should_receive(:coerce_callable).with(input).and_return(coerced)
29
- end
30
-
31
- it { should eql(coerced) }
32
- end
33
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Observer::NULL, '#call' do
4
- subject { object.call(input) }
5
-
6
- let(:object) { described_class }
7
- let(:input) { double }
8
-
9
- it_should_behave_like 'a command method'
10
-
11
- it { should be_kind_of(Observer) }
12
- end
@@ -1,49 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Processor::Evaluator, '#call' do
6
- subject { object.call(request) }
7
-
8
- let(:request) { Request.new(double('env'), input) }
9
-
10
- context "when no failure chain is registered" do
11
-
12
- let(:object) { described_class.new(Spec::FAKE_ENV, Spec::Handler::Evaluator.new) }
13
-
14
- context "when evaluation is successful" do
15
- let(:input) { :success }
16
- let(:response) { Response::Success.new(request, input) }
17
-
18
- it { should eql(response) }
19
- end
20
-
21
- context "when evaluation is not successful" do
22
- let(:input) { :invalid }
23
- let(:response) { Response::Failure.new(request, :failure) }
24
-
25
- it { should eql(response) }
26
- end
27
- end
28
-
29
- context "when a failure chain is registered" do
30
-
31
- let(:object) { described_class.new(env, Spec::Handler::Evaluator.new, &block) }
32
- let(:env) { Environment.new({}) }
33
- let(:block) { lambda { |_| use(Processor::Wrapper.new(env, Spec::Presenter)) } }
34
-
35
- context "when evaluation is successful" do
36
- let(:input) { :success }
37
- let(:response) { Response::Success.new(request, input) }
38
-
39
- it { should eql(response) }
40
- end
41
-
42
- context "when evaluation is not successful" do
43
- let(:input) { :invalid }
44
- let(:response) { Response::Failure.new(request, Spec::Presenter.new(:failure)) }
45
-
46
- it { should eql(response) }
47
- end
48
- end
49
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Processor::Pivot, '#call' do
6
- subject { object.call(request) }
7
-
8
- let(:object) { described_class.new(s_env, Spec::Handler::Pivot.new) }
9
- let(:s_env) { double }
10
- let(:request) { Request.new(env, input) }
11
- let(:env) { double }
12
- let(:input) { double }
13
-
14
- let(:response) { Response::Success.new(request, request.input) }
15
-
16
- it { should eql(response) }
17
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Processor::Wrapper, '#call' do
6
- subject { object.call(response) }
7
-
8
- let(:object) { described_class.new(s_env, Spec::Presenter) }
9
- let(:s_env) { double }
10
- let(:response) { Response::Success.new(request, output) }
11
- let(:request) { Request.new(env, input) }
12
- let(:env) { double }
13
- let(:input) { double }
14
- let(:output) { double }
15
-
16
- let(:wrapped) { Response::Success.new(request, data) }
17
- let(:data) { Spec::Presenter.new(output) }
18
-
19
- it { should eql(wrapped) }
20
- end
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Request, '#env' do
6
-
7
- subject { object.env }
8
-
9
- let(:object) { described_class.new(env, input) }
10
- let(:env) { double }
11
- let(:input) { double }
12
-
13
- it { should equal(env) }
14
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Request, '#error' do
6
-
7
- subject { object.error(output) }
8
-
9
- let(:object) { described_class.new(env, input) }
10
- let(:env) { double }
11
- let(:input) { double }
12
- let(:output) { double }
13
-
14
- it { should eql(Response::Failure.new(object, output)) }
15
- end
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Request, '#input' do
6
-
7
- subject { object.input }
8
-
9
- let(:object) { described_class.new(env, input) }
10
- let(:env) { double }
11
- let(:input) { double }
12
-
13
- it { should equal(input) }
14
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Request, '#success' do
6
-
7
- subject { object.success(output) }
8
-
9
- let(:object) { described_class.new(env, input) }
10
- let(:env) { double }
11
- let(:input) { double }
12
- let(:output) { double }
13
-
14
- it { should eql(Response::Success.new(object, output)) }
15
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Response, '#env' do
6
-
7
- subject { object.env }
8
-
9
- let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
11
- let(:env) { double }
12
- let(:input) { double }
13
- let(:output) { double }
14
-
15
- it { should equal(env) }
16
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Response::Failure, '#success?' do
6
- subject { object.success? }
7
-
8
- let(:object) { described_class.new(request, output) }
9
- let(:request) { Request.new(env, input) }
10
- let(:env) { double }
11
- let(:input) { double }
12
- let(:output) { double }
13
-
14
- it { should be(false) }
15
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Response, '#input' do
6
-
7
- subject { object.input }
8
-
9
- let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
11
- let(:env) { double }
12
- let(:input) { double }
13
- let(:output) { double }
14
-
15
- it { should equal(input) }
16
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Response, '#output' do
6
-
7
- subject { object.output }
8
-
9
- let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
11
- let(:env) { double }
12
- let(:input) { double }
13
- let(:output) { double }
14
-
15
- it { should equal(output) }
16
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Response, '#request' do
6
-
7
- subject { object.request }
8
-
9
- let(:object) { Class.new(described_class).new(request, output) }
10
- let(:request) { Request.new(env, input) }
11
- let(:env) { double }
12
- let(:input) { double }
13
- let(:output) { double }
14
-
15
- it { should equal(request) }
16
- end