Class: CMDx::Outputs

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeOutputs

Returns a new instance of Outputs.



11
12
13
# File 'lib/cmdx/outputs.rb', line 11

def initialize
  @registry = {}
end

Instance Attribute Details

#registryObject (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.

Parameters:

  • keys (Array<Symbol>)

Returns:



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

Returns:

  • (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.

Parameters:

  • source (Outputs)

    registry to duplicate



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`.

Parameters:

Options Hash (**options):

  • :description (String) — default: also accepts `:desc`
  • :if (Symbol, Proc, #call)
  • :unless (Symbol, Proc, #call)
  • :default (Object, Symbol, Proc, #call)

Returns:



30
31
32
33
34
35
36
37
# File 'lib/cmdx/outputs.rb', line 30

def register(*keys, **options)
  keys.each do |key|
    output = Output.new(key, **options)
    registry[output.name] = output
  end

  self
end

#sizeInteger

Returns:

  • (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`.

Parameters:



61
62
63
# File 'lib/cmdx/outputs.rb', line 61

def verify(task)
  registry.each_value { |output| output.verify(task) }
end