Module: Subroutine::Outputs

Extended by:
ActiveSupport::Concern
Included in:
Op
Defined in:
lib/subroutine/outputs.rb,
lib/subroutine/outputs/configuration.rb,
lib/subroutine/outputs/output_not_set_error.rb,
lib/subroutine/outputs/unknown_output_error.rb

Defined Under Namespace

Modules: ClassMethods Classes: Configuration, OutputNotSetError, UnknownOutputError

Instance Method Summary collapse

Instance Method Details

#get_output(name) ⇒ Object



61
62
63
64
65
66
# File 'lib/subroutine/outputs.rb', line 61

def get_output(name)
  name = name.to_sym
  raise ::Subroutine::Outputs::UnknownOutputError, name unless output_configurations.key?(name)

  outputs[name]
end

#output(name, value) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/subroutine/outputs.rb', line 52

def output(name, value)
  name = name.to_sym
  unless output_configurations.key?(name)
    raise ::Subroutine::Outputs::UnknownOutputError, name
  end

  outputs[name] = value
end

#output_provided?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
# File 'lib/subroutine/outputs.rb', line 42

def output_provided?(name)
  name = name.to_sym

  unless output_configurations.key?(name)
    raise ::Subroutine::Outputs::UnknownOutputError, name
  end

  outputs.key?(name)
end

#setup_outputsObject



38
39
40
# File 'lib/subroutine/outputs.rb', line 38

def setup_outputs
  @outputs = {} # don't do with_indifferent_access because it will turn provided objects into with_indifferent_access objects, which may not be the desired behavior
end

#validate_outputs!Object



68
69
70
71
72
73
74
# File 'lib/subroutine/outputs.rb', line 68

def validate_outputs!
  output_configurations.each_pair do |name, config|
    if config.required? && !output_provided?(name)
      raise ::Subroutine::Outputs::OutputNotSetError, name
    end
  end
end