Module: Operandi::Dsl::OutputsDsl::ClassMethods

Defined in:
lib/operandi/dsl/outputs_dsl.rb

Instance Method Summary collapse

Instance Method Details

#output(name, opts = {}) ⇒ Object

Define an output for the service

Examples:

Define a required hash output

output :result, type: Hash

Define an optional output with default

output :status, type: String, optional: true, default: "pending"

Define an output with multiple allowed types

output :data, type: [Hash, Array]

Define an output with proc default

output :metadata, type: Hash, default: -> { {} }

Parameters:

  • name (Symbol)

    the output name

  • opts (Hash) (defaults to: {})

    options for configuring the output

Options Hash (opts):

  • :type (Class, Array<Class>)

    Type(s) to validate against (e.g., Hash, String, [String, Symbol])

  • :optional (Boolean) — default: false

    Whether nil values are allowed

  • :default (Object, Proc)

    Default value or proc to evaluate in instance context



35
36
37
38
39
40
41
42
43
# File 'lib/operandi/dsl/outputs_dsl.rb', line 35

def output(name, opts = {})
  Validation.validate_symbol_name!(name, :output, self)
  Validation.validate_reserved_name!(name, :output, self)
  Validation.validate_name_conflicts!(name, :output, self)
  Validation.validate_type_required!(name, :output, self, opts)

  own_outputs[name] = Settings::Field.new(name, self, opts.merge(field_type: FieldTypes::OUTPUT))
  @outputs = nil # Clear memoized outputs since we're modifying them
end

#outputsHash

Get all outputs including inherited ones

Returns:

  • (Hash)

    all outputs defined for this service



56
57
58
# File 'lib/operandi/dsl/outputs_dsl.rb', line 56

def outputs
  @outputs ||= build_outputs
end

#own_outputsHash

Get only outputs defined in this class

Returns:

  • (Hash)

    outputs defined in this class only



63
64
65
# File 'lib/operandi/dsl/outputs_dsl.rb', line 63

def own_outputs
  @own_outputs ||= {}
end

#remove_output(name) ⇒ Object

Remove an output from the service

Parameters:

  • name (Symbol)

    the output name to remove



48
49
50
51
# File 'lib/operandi/dsl/outputs_dsl.rb', line 48

def remove_output(name)
  own_outputs.delete(name)
  @outputs = nil # Clear memoized outputs since we're modifying them
end