Class: CMDx::Outputs
- Inherits:
-
Object
- Object
- CMDx::Outputs
- Defined in:
- lib/cmdx/outputs.rb
Overview
Registry of declared task outputs. Runtime verifies each output after ‘work` completes: presence and defaults run against values the task wrote to context.
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#deregister(*keys) ⇒ Outputs
Self for chaining.
- #empty? ⇒ Boolean
-
#initialize ⇒ Outputs
constructor
A new instance of Outputs.
- #initialize_copy(source) ⇒ void
-
#register(*keys, **options) ⇒ Outputs
Declares one or more output keys.
- #size ⇒ Integer
-
#verify(task) ⇒ void
Verifies every declared output against ‘task.context`.
Constructor Details
#initialize ⇒ Outputs
Returns a new instance of Outputs.
11 12 13 |
# File 'lib/cmdx/outputs.rb', line 11 def initialize @registry = {} end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
9 10 11 |
# File 'lib/cmdx/outputs.rb', line 9 def registry @registry end |
Instance Method Details
#deregister(*keys) ⇒ Outputs
Returns self for chaining.
41 42 43 44 |
# File 'lib/cmdx/outputs.rb', line 41 def deregister(*keys) keys.each { |key| registry.delete(key.to_sym) } self end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/cmdx/outputs.rb', line 47 def empty? registry.empty? end |
#initialize_copy(source) ⇒ void
This method returns an undefined value.
17 18 19 |
# File 'lib/cmdx/outputs.rb', line 17 def initialize_copy(source) @registry = source.registry.dup end |
#register(*keys, **options) ⇒ Outputs
Declares one or more output keys. All share the same ‘options`.
30 31 32 33 34 35 36 37 |
# File 'lib/cmdx/outputs.rb', line 30 def register(*keys, **) keys.each do |key| output = Output.new(key, **) registry[output.name] = output end self end |
#size ⇒ Integer
52 53 54 |
# File 'lib/cmdx/outputs.rb', line 52 def size registry.size end |
#verify(task) ⇒ void
This method returns an undefined value.
Verifies every declared output against ‘task.context`. Adds any failures to `task.errors`.
61 62 63 |
# File 'lib/cmdx/outputs.rb', line 61 def verify(task) registry.each_value { |output| output.verify(task) } end |