Class: HatiCommand::Success

Inherits:
Result
  • Object
show all
Defined in:
lib/hati_command/success.rb

Overview

Represents a successful result in the Result pattern. This class is used to wrap successful operation values and provide a consistent interface for handling both successful and failed operations.

The Success class is part of the Result pattern implementation, working alongside the Failure class to provide a type-safe way to handle operation outcomes.

Examples:

Basic usage

success = HatiCommand::Success.new("Operation completed")
success.success?  # => true
success.failure?  # => false

With metadata

success = HatiCommand::Success.new(
  { id: 123, name: "Example" },
  meta: { duration_ms: 50 }
)
success.success  # => { id: 123, name: "Example" }

Pattern matching

case result
when HatiCommand::Success
  process_data(result.success)
end

See Also:

Instance Attribute Summary

Attributes inherited from Result

#err, #meta, #trace, #value

Instance Method Summary collapse

Methods inherited from Result

#error, #initialize, #result

Constructor Details

This class inherits a constructor from HatiCommand::Result

Instance Method Details

#failurenil

Returns nil since a Success has no failure value. This method is part of the Result pattern interface and always returns nil for Success instances.

Examples:

success = Success.new("Result")
success.failure  # => nil

Returns:

  • (nil)

    Always returns nil



67
68
69
# File 'lib/hati_command/success.rb', line 67

def failure
  nil
end

#failure?Boolean

Indicates that this is not a failure result. This method is part of the Result pattern interface and always returns false for Success instances.

Examples:

success = Success.new("Result")
success.failure?  # => false

Returns:

  • (Boolean)

    Always returns false



79
80
81
# File 'lib/hati_command/success.rb', line 79

def failure?
  false
end

#successObject

Returns the success value wrapped by this Success instance. This method provides access to the actual value or result that was produced by the successful operation.

Examples:

success = Success.new("Operation output")
success.success  # => "Operation output"

Returns:

  • (Object)

    The wrapped success value



43
44
45
# File 'lib/hati_command/success.rb', line 43

def success
  value
end

#success?Boolean

Indicates that this is a success result. This method is part of the Result pattern interface and always returns true for Success instances.

Examples:

success = Success.new("Result")
success.success?  # => true

Returns:

  • (Boolean)

    Always returns true



55
56
57
# File 'lib/hati_command/success.rb', line 55

def success?
  true
end

#to_symSymbol

Returns the symbolic representation of this result type. Useful for pattern matching and result type checking.

Examples:

success = Success.new("Result")
success.to_sym  # => :success

Returns:

  • (Symbol)

    Always returns :success



91
92
93
# File 'lib/hati_command/success.rb', line 91

def to_sym
  :success
end