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.
- data/.travis.yml +7 -3
- data/Changelog.md +99 -24
- data/Gemfile +8 -1
- data/Gemfile.devtools +37 -21
- data/Guardfile +1 -1
- data/README.md +118 -46
- data/TODO.md +1 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/reek.yml +41 -16
- data/config/rubocop.yml +44 -0
- data/config/yardstick.yml +1 -1
- data/lib/substation.rb +41 -5
- data/lib/substation/chain.rb +73 -84
- data/lib/substation/chain/definition.rb +147 -0
- data/lib/substation/chain/dsl.rb +150 -112
- data/lib/substation/chain/dsl/config.rb +55 -0
- data/lib/substation/chain/dsl/module_builder.rb +84 -0
- data/lib/substation/dispatcher.rb +20 -229
- data/lib/substation/dsl/guard.rb +96 -0
- data/lib/substation/dsl/registry.rb +181 -0
- data/lib/substation/environment.rb +126 -23
- data/lib/substation/environment/dsl.rb +31 -12
- data/lib/substation/processor.rb +238 -7
- data/lib/substation/processor/builder.rb +26 -0
- data/lib/substation/processor/config.rb +24 -0
- data/lib/substation/processor/evaluator.rb +66 -42
- data/lib/substation/processor/evaluator/handler.rb +54 -0
- data/lib/substation/processor/evaluator/result.rb +24 -0
- data/lib/substation/processor/executor.rb +46 -0
- data/lib/substation/processor/nest.rb +40 -0
- data/lib/substation/processor/transformer.rb +46 -0
- data/lib/substation/processor/wrapper.rb +16 -5
- data/lib/substation/request.rb +29 -27
- data/lib/substation/response.rb +19 -34
- data/lib/substation/response/api.rb +37 -0
- data/lib/substation/response/exception.rb +20 -0
- data/lib/substation/response/exception/output.rb +59 -0
- data/lib/substation/response/failure.rb +11 -0
- data/lib/substation/response/success.rb +11 -0
- data/lib/substation/version.rb +3 -1
- data/spec/demo/core.rb +64 -0
- data/spec/demo/core/action.rb +49 -0
- data/spec/demo/core/action/create_person.rb +28 -0
- data/spec/demo/core/errors.rb +16 -0
- data/spec/demo/core/facade.rb +38 -0
- data/spec/demo/core/handler.rb +21 -0
- data/spec/demo/core/handler/acceptor.rb +47 -0
- data/spec/demo/core/handler/authenticator.rb +36 -0
- data/spec/demo/core/handler/authorizer.rb +38 -0
- data/spec/demo/core/input.rb +15 -0
- data/spec/demo/core/observers.rb +10 -0
- data/spec/demo/core/validator.rb +21 -0
- data/spec/demo/domain/actor.rb +29 -0
- data/spec/demo/domain/dto/person.rb +18 -0
- data/spec/demo/domain/environment.rb +55 -0
- data/spec/demo/domain/storage.rb +49 -0
- data/spec/demo/web.rb +26 -0
- data/spec/demo/web/errors.rb +9 -0
- data/spec/demo/web/facade.rb +60 -0
- data/spec/demo/web/handler/deserializer.rb +36 -0
- data/spec/demo/web/presenter.rb +38 -0
- data/spec/demo/web/presenter/person.rb +19 -0
- data/spec/demo/web/renderer.rb +45 -0
- data/spec/demo/web/sanitizer.rb +35 -0
- data/spec/demo/web/sanitizer/person.rb +20 -0
- data/spec/demo/web/views.rb +28 -0
- data/spec/integration/demo/core_spec.rb +97 -0
- data/spec/integration/demo/web_spec.rb +114 -0
- data/spec/shared/context/integration/demo.rb +33 -0
- data/spec/shared/context/unit/chain.rb +13 -0
- data/spec/shared/context/unit/processor.rb +58 -0
- data/spec/shared/context/unit/request.rb +8 -0
- data/spec/shared/examples/integration/demo.rb +35 -0
- data/spec/shared/examples/unit/processor.rb +72 -0
- data/spec/spec_helper.rb +52 -23
- data/spec/unit/substation/chain/definition_spec.rb +141 -0
- data/spec/unit/substation/chain/dsl/config/dsl_module_spec.rb +13 -0
- data/spec/unit/substation/chain/dsl/config/registry_spec.rb +13 -0
- data/spec/unit/substation/chain/dsl/config_spec.rb +18 -0
- data/spec/unit/substation/chain/dsl/module_builder_spec.rb +77 -0
- data/spec/unit/substation/chain/dsl_spec.rb +175 -0
- data/spec/unit/substation/chain_spec.rb +303 -0
- data/spec/unit/substation/dispatcher_spec.rb +68 -0
- data/spec/unit/substation/dsl/guard_spec.rb +72 -0
- data/spec/unit/substation/dsl/registry_spec.rb +181 -0
- data/spec/unit/substation/environment/dsl_spec.rb +156 -0
- data/spec/unit/substation/environment_spec.rb +259 -0
- data/spec/unit/substation/processor/builder_spec.rb +21 -0
- data/spec/unit/substation/processor/config_spec.rb +40 -0
- data/spec/unit/substation/processor/evaluator/handler_spec.rb +20 -0
- data/spec/unit/substation/processor/evaluator/pivot_spec.rb +42 -0
- data/spec/unit/substation/processor/evaluator/request_spec.rb +11 -0
- data/spec/unit/substation/processor/evaluator/result/failure_spec.rb +14 -0
- data/spec/unit/substation/processor/evaluator/result/success_spec.rb +14 -0
- data/spec/unit/substation/processor/evaluator/result_spec.rb +13 -0
- data/spec/unit/substation/processor/evaluator_spec.rb +18 -0
- data/spec/unit/substation/processor/executor/null_spec.rb +25 -0
- data/spec/unit/substation/processor/executor_spec.rb +32 -0
- data/spec/unit/substation/processor/fallible_spec.rb +24 -0
- data/spec/unit/substation/processor/incoming_spec.rb +17 -0
- data/spec/unit/substation/processor/nest/incoming_spec.rb +56 -0
- data/spec/unit/substation/processor/nest_spec.rb +6 -0
- data/spec/unit/substation/processor/outgoing_spec.rb +47 -0
- data/spec/unit/substation/processor/transformer/incoming_spec.rb +17 -0
- data/spec/unit/substation/processor/transformer/outgoing_spec.rb +17 -0
- data/spec/unit/substation/processor/wrapper/incoming_spec.rb +15 -0
- data/spec/unit/substation/processor/wrapper/outgoing_spec.rb +15 -0
- data/spec/unit/substation/processor/wrapper_spec.rb +24 -0
- data/spec/unit/substation/processor_spec.rb +68 -0
- data/spec/unit/substation/request_spec.rb +70 -0
- data/spec/unit/substation/response/api_spec.rb +22 -0
- data/spec/unit/substation/response/exception/output_spec.rb +46 -0
- data/spec/unit/substation/response/exception_spec.rb +25 -0
- data/spec/unit/substation/response/failure_spec.rb +25 -0
- data/spec/unit/substation/response/success_spec.rb +24 -0
- data/spec/unit/substation/response_spec.rb +73 -0
- data/substation.gemspec +7 -6
- metadata +157 -67
- checksums.yaml +0 -7
- data/TODO +0 -0
- data/lib/substation/observer.rb +0 -66
- data/lib/substation/processor/pivot.rb +0 -25
- data/lib/substation/utils.rb +0 -68
- data/spec/integration/substation/dispatcher/call_spec.rb +0 -260
- data/spec/unit/substation/chain/call_spec.rb +0 -63
- data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +0 -19
- data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +0 -21
- data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +0 -30
- data/spec/unit/substation/chain/dsl/chain_spec.rb +0 -15
- data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +0 -24
- data/spec/unit/substation/chain/dsl/initialize_spec.rb +0 -19
- data/spec/unit/substation/chain/dsl/processors_spec.rb +0 -42
- data/spec/unit/substation/chain/dsl/use_spec.rb +0 -14
- data/spec/unit/substation/chain/each_spec.rb +0 -46
- data/spec/unit/substation/chain/incoming/result_spec.rb +0 -21
- data/spec/unit/substation/chain/outgoing/call_spec.rb +0 -25
- data/spec/unit/substation/chain/outgoing/result_spec.rb +0 -21
- data/spec/unit/substation/dispatcher/action/call_spec.rb +0 -23
- data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +0 -61
- data/spec/unit/substation/dispatcher/action_names_spec.rb +0 -14
- data/spec/unit/substation/dispatcher/call_spec.rb +0 -47
- data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +0 -20
- data/spec/unit/substation/environment/chain_spec.rb +0 -50
- data/spec/unit/substation/environment/class_methods/build_spec.rb +0 -11
- data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +0 -18
- data/spec/unit/substation/environment/dsl/register_spec.rb +0 -14
- data/spec/unit/substation/environment/dsl/registry_spec.rb +0 -19
- data/spec/unit/substation/observer/chain/call_spec.rb +0 -26
- data/spec/unit/substation/observer/class_methods/coerce_spec.rb +0 -33
- data/spec/unit/substation/observer/null/call_spec.rb +0 -12
- data/spec/unit/substation/processor/evaluator/call_spec.rb +0 -49
- data/spec/unit/substation/processor/pivot/call_spec.rb +0 -17
- data/spec/unit/substation/processor/wrapper/call_spec.rb +0 -20
- data/spec/unit/substation/request/env_spec.rb +0 -14
- data/spec/unit/substation/request/error_spec.rb +0 -15
- data/spec/unit/substation/request/input_spec.rb +0 -14
- data/spec/unit/substation/request/success_spec.rb +0 -15
- data/spec/unit/substation/response/env_spec.rb +0 -16
- data/spec/unit/substation/response/failure/success_predicate_spec.rb +0 -15
- data/spec/unit/substation/response/input_spec.rb +0 -16
- data/spec/unit/substation/response/output_spec.rb +0 -16
- data/spec/unit/substation/response/request_spec.rb +0 -16
- data/spec/unit/substation/response/success/success_predicate_spec.rb +0 -15
- data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +0 -46
- data/spec/unit/substation/utils/class_methods/const_get_spec.rb +0 -46
- data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +0 -20
@@ -0,0 +1,147 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Substation
|
4
|
+
class Chain
|
5
|
+
|
6
|
+
# Encapsulates an ordered list of {Processor} instances to be used
|
7
|
+
# within an instance of {Chain}
|
8
|
+
class Definition
|
9
|
+
|
10
|
+
include Equalizer.new(:name, :processors)
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
# The message for {UnknownProcessor} exceptions
|
14
|
+
UNKNOWN_PROCESSOR_MSG = 'No processor named %s is registered'.freeze
|
15
|
+
|
16
|
+
# The message for {DuplicateProcessorError} exceptions
|
17
|
+
DUPLICATE_PROCESSOR_MSG = 'The following processors already exist within this chain: %s'
|
18
|
+
|
19
|
+
# The name of the chain
|
20
|
+
#
|
21
|
+
# @return [Symbol]
|
22
|
+
#
|
23
|
+
# @api private
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
# The processors used in this instance
|
27
|
+
#
|
28
|
+
# @return [Enumerable<#call>]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
attr_reader :processors
|
32
|
+
protected :processors
|
33
|
+
|
34
|
+
# Initialize a new instance
|
35
|
+
#
|
36
|
+
# @param [Enumerable<#call>] processors
|
37
|
+
# the processors to be used within this instance
|
38
|
+
#
|
39
|
+
# @return [undefined]
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
def initialize(name, processors)
|
43
|
+
@name, @processors = name, []
|
44
|
+
processors.each(&method(:<<))
|
45
|
+
end
|
46
|
+
|
47
|
+
# Append +processor+ to {#processors}
|
48
|
+
#
|
49
|
+
# @param [#call] processor
|
50
|
+
# the processor to append
|
51
|
+
#
|
52
|
+
# @return [self]
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
def <<(processor)
|
56
|
+
raise_duplicate_processor_error([processor]) if include?(processor)
|
57
|
+
processors << processor
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
# The following const MUST have #initialize and #<< defined already
|
62
|
+
|
63
|
+
# An empty instance
|
64
|
+
EMPTY = new(nil, EMPTY_ARRAY).freeze
|
65
|
+
|
66
|
+
# Replace the failure chain of the processor identified by +name+
|
67
|
+
#
|
68
|
+
# @param [Symbol] processor_name
|
69
|
+
# the name of the processor
|
70
|
+
#
|
71
|
+
# @param [Chain] failure_chain
|
72
|
+
# the failure chain to use in the replaced processor
|
73
|
+
#
|
74
|
+
# @return [self]
|
75
|
+
#
|
76
|
+
# @api private
|
77
|
+
def replace_failure_chain(processor_name, failure_chain)
|
78
|
+
idx = fetch(processor_name)
|
79
|
+
processors[idx] = processors.at(idx).with_failure_chain(failure_chain)
|
80
|
+
self
|
81
|
+
end
|
82
|
+
|
83
|
+
# Iterate over all processors
|
84
|
+
#
|
85
|
+
# @param [Proc] block
|
86
|
+
# a block passed to #{processors} each method
|
87
|
+
#
|
88
|
+
# @yield [processor]
|
89
|
+
#
|
90
|
+
# @yieldparam [#call] processor
|
91
|
+
# each processor in this instance
|
92
|
+
#
|
93
|
+
# @return [self]
|
94
|
+
#
|
95
|
+
# @api private
|
96
|
+
def each(&block)
|
97
|
+
return to_enum unless block
|
98
|
+
processors.each(&block)
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns a new instance with +other+'s processors prepended
|
103
|
+
#
|
104
|
+
# @param [Definition] other
|
105
|
+
# the definition to prepend
|
106
|
+
#
|
107
|
+
# @return [Definition]
|
108
|
+
#
|
109
|
+
# @api private
|
110
|
+
def prepend(other)
|
111
|
+
duplicates = processors & other.processors
|
112
|
+
raise_duplicate_processor_error(duplicates) if duplicates.any?
|
113
|
+
self.class.new(name, other.processors | processors)
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
# Return the index for a processor with the given +name+
|
119
|
+
#
|
120
|
+
# @param [Symbol] name
|
121
|
+
# the processor's name
|
122
|
+
#
|
123
|
+
# @return [Integer]
|
124
|
+
#
|
125
|
+
# @raise [UnknownProcessor]
|
126
|
+
#
|
127
|
+
# @api private
|
128
|
+
def fetch(processor_name)
|
129
|
+
processors.index {|processor| processor.name == processor_name} ||
|
130
|
+
raise(UnknownProcessor, UNKNOWN_PROCESSOR_MSG % processor_name.inspect)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Raise {DuplicateProcessorError} with a message tailored for +dupes+
|
134
|
+
#
|
135
|
+
# @param [Processor, Array<Processor>] dupes
|
136
|
+
# one or many duplicate processors
|
137
|
+
#
|
138
|
+
# @raise [DuplicateProcessorError]
|
139
|
+
#
|
140
|
+
# @api private
|
141
|
+
def raise_duplicate_processor_error(dupes)
|
142
|
+
raise DuplicateProcessorError, DUPLICATE_PROCESSOR_MSG % dupes.inspect
|
143
|
+
end
|
144
|
+
|
145
|
+
end # class Definition
|
146
|
+
end # class Chain
|
147
|
+
end # module Substation
|
data/lib/substation/chain/dsl.rb
CHANGED
@@ -1,162 +1,200 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Substation
|
2
4
|
class Chain
|
3
5
|
|
4
6
|
# The DSL class used to define chains in an {Environment}
|
5
7
|
class DSL
|
6
8
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# @return [Class<DSL>]
|
17
|
-
#
|
18
|
-
# @api private
|
19
|
-
def self.call(registry)
|
20
|
-
new(registry).dsl
|
21
|
-
end
|
22
|
-
|
23
|
-
# The built DSL subclass
|
24
|
-
#
|
25
|
-
# @return [Class<DSL>]
|
26
|
-
#
|
27
|
-
# @api private
|
28
|
-
attr_reader :dsl
|
29
|
-
|
30
|
-
# Initialize a new instance
|
31
|
-
#
|
32
|
-
# @param [Hash<Symbol, #call>] registry
|
33
|
-
# the registry of processors used in an {Environment}
|
34
|
-
#
|
35
|
-
# @return [undefined]
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
def initialize(registry)
|
39
|
-
@registry = registry
|
40
|
-
@dsl = compile_dsl
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
# Compile a new DSL class
|
46
|
-
#
|
47
|
-
# @return [Class<DSL>]
|
48
|
-
#
|
49
|
-
# @api private
|
50
|
-
def compile_dsl
|
51
|
-
@registry.each_with_object(Class.new(DSL)) { |(name, processor), dsl|
|
52
|
-
define_dsl_method(name, processor, dsl)
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
# Define a new instance method on the +dsl+ class
|
58
|
-
#
|
59
|
-
# @param [Symbol] name
|
60
|
-
# the name of the method
|
61
|
-
#
|
62
|
-
# @param [#call] processor
|
63
|
-
# the processor to use within the chain
|
64
|
-
#
|
65
|
-
# @param [Class<DSL>] dsl
|
66
|
-
# the {DSL} subclass to define the method on
|
67
|
-
#
|
68
|
-
# @return [undefined]
|
69
|
-
#
|
70
|
-
# @api private
|
71
|
-
def define_dsl_method(name, processor, dsl)
|
72
|
-
dsl.class_eval do
|
73
|
-
define_method(name) do |*args, &block|
|
74
|
-
use(processor.new(env, *args, &block))
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end # class Builder
|
80
|
-
|
81
|
-
# The processors to be used within a {Chain}
|
82
|
-
#
|
83
|
-
# @return [Array<#call>]
|
9
|
+
# Build a new instance suitable for +registry+
|
10
|
+
#
|
11
|
+
# @param [Hash<Symbol, Processor>] registry
|
12
|
+
# the registry of processor builders to use in a {Chain}
|
13
|
+
#
|
14
|
+
# @param [Definition] definition
|
15
|
+
# the collection of processors to use in a {Chain}
|
16
|
+
#
|
17
|
+
# @return [DSL]
|
84
18
|
#
|
85
19
|
# @api private
|
86
|
-
|
20
|
+
def self.build(registry, definition = Definition::EMPTY)
|
21
|
+
new(Config.build(registry), definition)
|
22
|
+
end
|
87
23
|
|
88
|
-
|
24
|
+
include Equalizer.new(:registry, :definition)
|
25
|
+
|
26
|
+
# The chain's name
|
89
27
|
#
|
90
|
-
# @
|
91
|
-
# the substation environment used to build chains
|
28
|
+
# @return [#to_sym]
|
92
29
|
#
|
93
|
-
# @
|
94
|
-
|
30
|
+
# @api public
|
31
|
+
attr_reader :name
|
32
|
+
|
33
|
+
# The config for this instance
|
95
34
|
#
|
96
|
-
# @
|
97
|
-
# a block to be instance_eval'ed
|
35
|
+
# @return [Config]
|
98
36
|
#
|
99
|
-
# @
|
37
|
+
# @api private
|
38
|
+
attr_reader :config
|
39
|
+
|
40
|
+
# The definition to be used within a {Chain}
|
41
|
+
#
|
42
|
+
# @return [Definition]
|
100
43
|
#
|
101
44
|
# @api private
|
102
|
-
|
103
|
-
|
104
|
-
|
45
|
+
attr_reader :definition
|
46
|
+
|
47
|
+
# The registry used to build processors
|
48
|
+
#
|
49
|
+
# @return [Hash<Symbol, Processor::Builder>]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
attr_reader :registry
|
105
53
|
|
106
54
|
# Initialize a new instance
|
107
55
|
#
|
108
|
-
#
|
109
|
-
#
|
56
|
+
# Extends the new instance with methods defined in +config.dsl_module+.
|
57
|
+
# Only happens during boot, once for every instantiated {Environment}.
|
110
58
|
#
|
111
|
-
# @param [
|
112
|
-
#
|
59
|
+
# @param [Config] config
|
60
|
+
# a config for this instance
|
113
61
|
#
|
114
|
-
# @param [
|
115
|
-
#
|
62
|
+
# @param [Definition] definition
|
63
|
+
# the definition to use within a {Chain}
|
116
64
|
#
|
117
65
|
# @return [undefined]
|
118
66
|
#
|
119
67
|
# @api private
|
120
|
-
def initialize(
|
121
|
-
@
|
122
|
-
|
123
|
-
|
68
|
+
def initialize(config, definition)
|
69
|
+
@config = config
|
70
|
+
@definition = definition
|
71
|
+
@registry = @config.registry
|
72
|
+
@name = @definition.name
|
73
|
+
|
74
|
+
extend(@config.dsl_module)
|
124
75
|
end
|
125
76
|
|
126
|
-
#
|
77
|
+
# Build a new {Chain} based on +other+, a +failure_chain+ and a block
|
127
78
|
#
|
128
|
-
# @param [#
|
129
|
-
#
|
79
|
+
# @param [#to_sym] name
|
80
|
+
# the name of the chain to build
|
81
|
+
#
|
82
|
+
# @param [Enumerable<#call>] other
|
83
|
+
# the processors to prepend
|
84
|
+
#
|
85
|
+
# @param [Chain] exception_chain
|
86
|
+
# the chain to invoke in case of an uncaught exception
|
87
|
+
#
|
88
|
+
# @param [Proc] block
|
89
|
+
# a block to be instance_eval'ed inside the new {DSL} instance
|
90
|
+
#
|
91
|
+
# @return [Chain]
|
92
|
+
#
|
93
|
+
# @api private
|
94
|
+
def build(name, other, exception_chain, &block)
|
95
|
+
Chain.new(__call__(Definition.new(name, other), &block), exception_chain)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Append the given chain
|
99
|
+
#
|
100
|
+
# @param [Enumerable<#call>] processors
|
101
|
+
# other processors to be nested within a {Definition}
|
130
102
|
#
|
131
103
|
# @return [self]
|
132
104
|
#
|
133
105
|
# @api private
|
134
|
-
def
|
135
|
-
|
106
|
+
def chain(processors, &block)
|
107
|
+
processors.each(&method(:use))
|
108
|
+
instance_eval(&block) if block
|
136
109
|
self
|
137
110
|
end
|
138
111
|
|
139
|
-
# Nest the given chain
|
112
|
+
# Nest the given chain at the end of the current one
|
113
|
+
#
|
114
|
+
# @param [#to_sym] name
|
115
|
+
# the name of the nested chain
|
116
|
+
#
|
117
|
+
# @param [Enumerable<#call>] chain
|
118
|
+
# the chain to nest
|
119
|
+
#
|
120
|
+
# @param [Processor::Executor] executor
|
121
|
+
# the executor used for nesting
|
122
|
+
#
|
123
|
+
# @return [Processor::Nest::Incoming]
|
124
|
+
#
|
125
|
+
# @api private
|
126
|
+
def nest(name, chain, executor)
|
127
|
+
config = Processor::Config.new(executor, EMPTY_ARRAY, EMPTY_ARRAY)
|
128
|
+
use(Processor::Nest::Incoming.new(name, chain, config))
|
129
|
+
end
|
130
|
+
|
131
|
+
# Use +chain+ as the failure chain for the processor identified by +name+
|
140
132
|
#
|
141
|
-
# @param [
|
142
|
-
#
|
133
|
+
# @param [Symbol] name
|
134
|
+
# the processor's name
|
135
|
+
#
|
136
|
+
# @param [Chain] failure_chain
|
137
|
+
# the failure chain to use for the processor identified by +name+
|
143
138
|
#
|
144
139
|
# @return [self]
|
145
140
|
#
|
146
141
|
# @api private
|
147
|
-
def
|
148
|
-
|
142
|
+
def failure_chain(name, failure_chain)
|
143
|
+
definition.replace_failure_chain(name, failure_chain)
|
149
144
|
self
|
150
145
|
end
|
151
146
|
|
152
147
|
private
|
153
148
|
|
154
|
-
#
|
149
|
+
# Use the given +processor+ within a chain
|
150
|
+
#
|
151
|
+
# @param [#call] processor
|
152
|
+
# a processor to use within a chain
|
155
153
|
#
|
156
|
-
# @return [
|
154
|
+
# @return [#call]
|
155
|
+
# the added processor
|
157
156
|
#
|
158
157
|
# @api private
|
159
|
-
|
158
|
+
def use(processor)
|
159
|
+
definition << processor
|
160
|
+
processor
|
161
|
+
end
|
162
|
+
|
163
|
+
# Return a new definition
|
164
|
+
#
|
165
|
+
# @param [Definition] other
|
166
|
+
# the definition to prepend
|
167
|
+
#
|
168
|
+
# @param [Proc] block
|
169
|
+
# a block to be instance_eval'd inside a new {DSL} instance
|
170
|
+
#
|
171
|
+
# @return [Definition]
|
172
|
+
# the definition to be used with a {Chain}
|
173
|
+
#
|
174
|
+
# @api private
|
175
|
+
def __call__(other, &block)
|
176
|
+
instance = new(other)
|
177
|
+
instance.instance_eval(&block) if block
|
178
|
+
instance.definition
|
179
|
+
end
|
180
|
+
|
181
|
+
# Instantiate a new instance
|
182
|
+
#
|
183
|
+
# @param [Definition] other
|
184
|
+
# the definition to prepend
|
185
|
+
#
|
186
|
+
# @param [Proc] block
|
187
|
+
# a block to be instance_eval'd inside a new {DSL} instance
|
188
|
+
#
|
189
|
+
# @return [DSL]
|
190
|
+
#
|
191
|
+
# @api private
|
192
|
+
def new(other)
|
193
|
+
self.class.new(config, other.prepend(definition))
|
194
|
+
end
|
195
|
+
|
196
|
+
# All methods defined in this class body
|
197
|
+
BASE_METHODS = methods.freeze
|
160
198
|
|
161
199
|
end # class DSL
|
162
200
|
end # class Chain
|