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.
-
#freeze ⇒ self
Prevents further modifications to this operation and its config.
- #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
344 345 346 347 348 349 350 |
# File 'lib/teckel/operation/config.rb', line 344 def clone if frozen? super() else dup_config(super()) end end |
#default_settings ⇒ nil|#call
Getter for configured default settings
230 231 232 |
# File 'lib/teckel/operation/config.rb', line 230 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.
218 219 220 221 222 223 224 225 226 |
# File 'lib/teckel/operation/config.rb', line 218 def default_settings!(*args) callable = if args.size.equal?(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.
336 337 338 |
# File 'lib/teckel/operation/config.rb', line 336 def dup dup_config(super()) end |
#error ⇒ Class #error(klass) ⇒ Class?
116 117 118 119 |
# File 'lib/teckel/operation/config.rb', line 116 def error(klass = nil) @config.for(:error, klass) { self::Error if const_defined?(:Error) } || raise(MissingConfigError, "Missing error config for #{self}") end |
#error_constructor ⇒ Proc #error_constructor(sym_or_proc) ⇒ #call
148 149 150 |
# File 'lib/teckel/operation/config.rb', line 148 def error_constructor(sym_or_proc = nil) get_set_constructor(:error_constructor, error, sym_or_proc) end |
#finalize! ⇒ self
Disallow any further changes to this Operation. Make sure all configurations are set.
326 327 328 329 330 |
# File 'lib/teckel/operation/config.rb', line 326 def finalize! define! @config.freeze self end |
#freeze ⇒ self
Prevents further modifications to this operation and its config
356 357 358 359 |
# File 'lib/teckel/operation/config.rb', line 356 def freeze @config.freeze super() 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(MissingConfigError, "Missing input config for #{self}") end |
#input_constructor ⇒ Proc #input_constructor(sym_or_proc) ⇒ #call
59 60 61 |
# File 'lib/teckel/operation/config.rb', line 59 def input_constructor(sym_or_proc = nil) get_set_constructor(:input_constructor, input, sym_or_proc) end |
#output ⇒ Class #output(klass) ⇒ Class
72 73 74 75 |
# File 'lib/teckel/operation/config.rb', line 72 def output(klass = nil) @config.for(:output, klass) { self::Output if const_defined?(:Output) } || raise(MissingConfigError, "Missing output config for #{self}") end |
#output_constructor ⇒ Proc #output_constructor(sym_or_proc) ⇒ #call
104 105 106 |
# File 'lib/teckel/operation/config.rb', line 104 def output_constructor(sym_or_proc = nil) get_set_constructor(:output_constructor, output, sym_or_proc) end |
#result ⇒ Class #result(klass) ⇒ Class
256 257 258 |
# File 'lib/teckel/operation/config.rb', line 256 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.
297 298 299 300 301 |
# File 'lib/teckel/operation/config.rb', line 297 def result! @config.for(:result, Result) @config.for(:result_constructor, Result.method(:new)) nil end |
#result_constructor ⇒ Proc #result_constructor(sym_or_proc) ⇒ #call
284 285 286 287 |
# File 'lib/teckel/operation/config.rb', line 284 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
242 243 244 |
# File 'lib/teckel/operation/config.rb', line 242 def runner(klass = nil) @config.for(:runner, klass) { Runner } end |
#settings ⇒ Class #settings(klass) ⇒ Class
162 163 164 |
# File 'lib/teckel/operation/config.rb', line 162 def settings(klass = nil) @config.for(:settings, klass) { const_defined?(:Settings) ? self::Settings : none } end |
#settings_constructor ⇒ Proc #settings_constructor(sym_or_proc) ⇒ #call
189 190 191 192 |
# File 'lib/teckel/operation/config.rb', line 189 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 |