Module: Teckel::Operation::Config
- Defined in:
- lib/teckel/operation/config.rb
Shortcuts collapse
-
#clone ⇒ self
Produces a clone of this operation and all it’s configuration.
-
#dup ⇒ self
Produces a shallow copy of this operation and all it’s configuration.
-
#finalize! ⇒ self
Disallow any further changes to this Operation.
- #result! ⇒ nil protected
Instance Method Summary collapse
-
#default_settings ⇒ nil|#call
Getter for configured default settings.
-
#default_settings!(*args) ⇒ Object
Declare default settings this operation should use when called without #with.
- #error(klass = nil) ⇒ Object
- #error_constructor(sym_or_proc = nil) ⇒ Object
- #input(klass = nil) ⇒ Object
- #input_constructor(sym_or_proc = nil) ⇒ Object
- #output(klass = nil) ⇒ Object
- #output_constructor(sym_or_proc = nil) ⇒ Object
- #result(klass = nil) ⇒ Object
- #result_constructor(sym_or_proc = nil) ⇒ Object
- #runner(klass = nil) ⇒ Object
- #settings(klass = nil) ⇒ Object
- #settings_constructor(sym_or_proc = nil) ⇒ Object
Instance Method Details
#clone ⇒ self
Produces a clone of this operation and all it’s configuration
352 353 354 355 356 357 358 359 360 |
# File 'lib/teckel/operation/config.rb', line 352 def clone if frozen? super else super.tap do |copy| copy.instance_variable_set(:@config, @config.dup) end end end |
#default_settings ⇒ nil|#call
Getter for configured default settings
236 237 238 |
# File 'lib/teckel/operation/config.rb', line 236 def default_settings @config.for(:default_settings) end |
#default_settings! ⇒ Object #default_settings!(sym_or_proc) ⇒ Object #default_settings!(arg1, arg2, ...) ⇒ Object
Declare default settings this operation should use when called without #with. When executing a Operation, settings will no longer be nil, but whatever you define here.
Explicit call-time settings will not get merged with declared default setting.
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/teckel/operation/config.rb', line 221 def default_settings!(*args) callable = if args.empty? -> { settings_constructor.call } elsif args.length == 1 build_constructor(settings, args.first) end callable ||= -> { settings_constructor.call(*args) } @config.for(:default_settings, callable) end |
#dup ⇒ self
Produces a shallow copy of this operation and all it’s configuration.
342 343 344 345 346 |
# File 'lib/teckel/operation/config.rb', line 342 def dup super.tap do |copy| copy.instance_variable_set(:@config, @config.dup) end end |
#error ⇒ Class #error(klass) ⇒ Class?
118 119 120 121 |
# File 'lib/teckel/operation/config.rb', line 118 def error(klass = nil) @config.for(:error, klass) { self::Error if const_defined?(:Error) } || raise(Teckel::MissingConfigError, "Missing error config for #{self}") end |
#error_constructor ⇒ Proc #error_constructor(sym_or_proc) ⇒ #call
150 151 152 153 |
# File 'lib/teckel/operation/config.rb', line 150 def error_constructor(sym_or_proc = nil) get_set_constructor(:error_constructor, error, sym_or_proc) || raise(MissingConfigError, "Missing error_constructor config for #{self}") end |
#finalize! ⇒ self
Disallow any further changes to this Operation. Make sure all configurations are set.
332 333 334 335 336 |
# File 'lib/teckel/operation/config.rb', line 332 def finalize! define! @config.freeze self end |
#input ⇒ Class #input(klass) ⇒ Class
13 14 15 16 |
# File 'lib/teckel/operation/config.rb', line 13 def input(klass = nil) @config.for(:input, klass) { self::Input if const_defined?(:Input) } || raise(Teckel::MissingConfigError, "Missing input config for #{self}") end |
#input_constructor ⇒ Proc #input_constructor(sym_or_proc) ⇒ #call
59 60 61 62 |
# File 'lib/teckel/operation/config.rb', line 59 def input_constructor(sym_or_proc = nil) get_set_constructor(:input_constructor, input, sym_or_proc) || raise(MissingConfigError, "Missing input_constructor config for #{self}") end |
#output ⇒ Class #output(klass) ⇒ Class
73 74 75 76 |
# File 'lib/teckel/operation/config.rb', line 73 def output(klass = nil) @config.for(:output, klass) { self::Output if const_defined?(:Output) } || raise(Teckel::MissingConfigError, "Missing output config for #{self}") end |
#output_constructor ⇒ Proc #output_constructor(sym_or_proc) ⇒ #call
105 106 107 108 |
# File 'lib/teckel/operation/config.rb', line 105 def output_constructor(sym_or_proc = nil) get_set_constructor(:output_constructor, output, sym_or_proc) || raise(MissingConfigError, "Missing output_constructor config for #{self}") end |
#result ⇒ Class #result(klass) ⇒ Class
262 263 264 |
# File 'lib/teckel/operation/config.rb', line 262 def result(klass = nil) @config.for(:result, klass) { const_defined?(:Result, false) ? self::Result : ValueResult } end |
#result! ⇒ nil (protected)
Don’t use in conjunction with #result or #result_constructor
Shortcut to use Result as a result object, wrapping any #error or #output.
303 304 305 306 307 |
# File 'lib/teckel/operation/config.rb', line 303 def result! @config.for(:result, Teckel::Operation::Result) @config.for(:result_constructor, Teckel::Operation::Result.method(:new)) nil end |
#result_constructor ⇒ Proc #result_constructor(sym_or_proc) ⇒ #call
290 291 292 293 |
# File 'lib/teckel/operation/config.rb', line 290 def result_constructor(sym_or_proc = nil) get_set_constructor(:result_constructor, result, sym_or_proc) || raise(MissingConfigError, "Missing result_constructor config for #{self}") end |
#runner ⇒ Class #runner(klass) ⇒ Object
248 249 250 |
# File 'lib/teckel/operation/config.rb', line 248 def runner(klass = nil) @config.for(:runner, klass) { Teckel::Operation::Runner } end |
#settings ⇒ Class #settings(klass) ⇒ Class
165 166 167 |
# File 'lib/teckel/operation/config.rb', line 165 def settings(klass = nil) @config.for(:settings, klass) { const_defined?(:Settings) ? self::Settings : none } end |
#settings_constructor ⇒ Proc #settings_constructor(sym_or_proc) ⇒ #call
192 193 194 195 |
# File 'lib/teckel/operation/config.rb', line 192 def settings_constructor(sym_or_proc = nil) get_set_constructor(:settings_constructor, settings, sym_or_proc) || raise(MissingConfigError, "Missing settings_constructor config for #{self}") end |