Module: Teckel::Chain::Config
- Defined in:
- lib/teckel/chain/config.rb
Constant Summary collapse
- REQUIRED_CONFIGS =
%i[around runner result result_constructor].freeze
Instance Attribute Summary collapse
-
#runner() ⇒ Class
readonly
protected
The Runner class.
Instance Method Summary collapse
-
#around(callable = nil, &block) ⇒ Proc, {#call}
Set or get the optional around hook.
-
#clone ⇒ self
Produces a clone of this chain.
-
#default_settings ⇒ nil|#call
Getter for configured default settings.
-
#default_settings!(settings) ⇒ Object
Declare default settings operation iin this chain should use when called without #with.
-
#dup ⇒ self
Produces a shallow copy of this chain.
-
#finalize! ⇒ self
Disallow any further changes to this Chain.
- #result(klass = nil) ⇒ Object
- #result_constructor(sym_or_proc = nil) ⇒ Object
-
#runner(klass = nil) ⇒ Object
protected
Overwrite the default runner.
-
#step(name, operation) ⇒ Object
Declare a Operation as a named step.
-
#steps ⇒ <Step>
Get the list of defined steps.
Instance Attribute Details
#runner() ⇒ Class (readonly, protected)
Returns The Runner class.
|
# File 'lib/teckel/chain/config.rb', line 68
|
Instance Method Details
#around(callable = nil, &block) ⇒ Proc, {#call}
Set or get the optional around hook. A Hook might be given as a block or anything callable. The execution of the chain is yielded to this hook. The first argument being the callable chain (Runner) and the second argument the input
data. The hook also needs to return the result.
64 65 66 |
# File 'lib/teckel/chain/config.rb', line 64 def around(callable = nil, &block) @config.for(:around, callable || block) end |
#clone ⇒ self
238 239 240 241 242 243 244 |
# File 'lib/teckel/chain/config.rb', line 238 def clone if frozen? super else dup_config(super) end end |
#default_settings ⇒ nil|#call
Getter for configured default settings
196 197 198 |
# File 'lib/teckel/chain/config.rb', line 196 def default_settings @config.for(:default_settings) end |
#default_settings!(settings) ⇒ Object
Declare default settings operation iin this chain should use when called without #with.
Explicit call-time settings will not get merged with declared default setting.
190 191 192 |
# File 'lib/teckel/chain/config.rb', line 190 def default_settings!(settings) # :nodoc: The bang is for consistency with the Operation class @config.for(:default_settings, settings) end |
#dup ⇒ self
229 230 231 |
# File 'lib/teckel/chain/config.rb', line 229 def dup dup_config(super) end |
#finalize! ⇒ self
This also calls finalize!
on all Operations defined as steps.
Disallow any further changes to this Chain.
217 218 219 220 221 222 |
# File 'lib/teckel/chain/config.rb', line 217 def finalize! define! steps.freeze @config.freeze self end |
#result ⇒ Class #result(klass) ⇒ Class
87 88 89 |
# File 'lib/teckel/chain/config.rb', line 87 def result(klass = nil) @config.for(:result, klass) { const_defined?(:Result, false) ? self::Result : Teckel::Chain::Result } end |
#result_constructor ⇒ Proc #result_constructor(sym_or_proc) ⇒ #call
143 144 145 146 147 148 149 |
# File 'lib/teckel/chain/config.rb', line 143 def result_constructor(sym_or_proc = nil) constructor = build_constructor(result, sym_or_proc) unless sym_or_proc.nil? @config.for(:result_constructor, constructor) { build_constructor(result, Teckel::DEFAULT_CONSTRUCTOR) } || raise(MissingConfigError, "Missing result_constructor config for #{self}") end |
#runner(klass = nil) ⇒ Object (protected)
Overwrite the default runner
75 76 77 |
# File 'lib/teckel/chain/config.rb', line 75 def runner(klass = nil) @config.for(:runner, klass) { Runner } end |
#step(name, operation) ⇒ Object
Declare a Operation as a named step
12 13 14 |
# File 'lib/teckel/chain/config.rb', line 12 def step(name, operation) steps << Step.new(name, operation) end |
#steps ⇒ <Step>
Get the list of defined steps
19 20 21 |
# File 'lib/teckel/chain/config.rb', line 19 def steps @config.for(:steps) { [] } end |