Class: Domainic::Command::Context::OutputContext

Inherits:
Object
  • Object
show all
Includes:
Behavior
Defined in:
lib/domainic/command/context/output_context.rb

Overview

A context class for managing command output values. This class provides a structured way to define, validate, and access the return values from commands.

Examples:

class MyOutputContext < Domainic::Command::Context::OutputContext
  field :processed_name, String, "The processed name"
  field :status, Symbol, default: :success
end

Author:

Since:

  • 0.1.0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.field(name, *type_validator_and_description, **options) ⇒ void

Defines a return value for the command

This method returns an undefined value.

Parameters:

  • name (String, Symbol)

    The name of the return value

  • type_validator_and_description (Array<Class, Module, Object, Proc, String, nil>)

    Type validator or description arguments

  • options (Hash)

    Configuration options for the return value

Options Hash (**options):

  • :default (Object)

    A static default value

  • :default_generator (Proc)

    A proc that generates the default value

  • :default_value (Object)

    Alias for :default

  • :desc (String, nil)

    Short description of the return value

  • :description (String, nil)

    Full description of the return value

  • :required (Boolean)

    Whether the return value is required

  • :type (Class, Module, Object, Proc)

    A type validator

Since:

  • 0.1.0



51
# File 'lib/domainic/command/context/output_context.rb', line 51

def self.field(...) = attribute(...)

Instance Method Details

#initialize(**options) ⇒ Behavior Originally defined in module Behavior

Initializes a new context instance with the given attributes.

Parameters:

  • options (Hash{String, Symbol => Object})

    Attribute values for initialization

Returns:

Raises:

  • (ArgumentError)

    If any attribute values are invalid

Since:

  • 0.1.0

#to_hashHash{Symbol => Object} Also known as: to_h Originally defined in module Behavior

Returns a hash of all attribute names and their values.

Returns:

  • (Hash{Symbol => Object})

    A hash of attribute values

Since:

  • 0.1.0