Module: HatiCommand::Cmd
- Defined in:
- lib/hati_command/cmd.rb
Overview
Dev-friendly extension of the Befehl core module with Railway track API. This module provides a Railway-oriented programming interface for handling success and failure states in a functional way, making it easier to chain operations and handle errors gracefully.
Class Method Summary collapse
-
.included(base) ⇒ void
Includes the module in the base class and sets up necessary configurations.
-
.whoami ⇒ String
Returns the identity of the module.
Instance Method Summary collapse
-
#Failure(value = nil, err: nil, meta: {}) ⇒ HatiCommand::Failure
Creates a Failure monad representing a failed operation.
-
#Failure!(value = nil, err: nil, meta: {}, **_opts) ⇒ Object
Creates a Failure monad and immediately raises a FailFastError.
-
#Success(value = nil, err: nil, meta: {}) ⇒ HatiCommand::Success
Creates a Success monad representing a successful operation.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Includes the module in the base class and sets up necessary configurations
28 29 30 31 |
# File 'lib/hati_command/cmd.rb', line 28 def self.included(base) base.extend(HatiCommand::Befehl) base.private_class_method :new end |
.whoami ⇒ String
This is a work in progress method
Returns the identity of the module
37 38 39 |
# File 'lib/hati_command/cmd.rb', line 37 def self.whoami 'My Name is Cmd' end |
Instance Method Details
#Failure(value = nil, err: nil, meta: {}) ⇒ HatiCommand::Failure
Creates a Failure monad representing a failed operation
59 60 61 62 |
# File 'lib/hati_command/cmd.rb', line 59 def Failure(value = nil, err: nil, meta: {}) # rubocop:disable Naming/MethodName default_err = self.class.command_config[:failure] HatiCommand::Failure.new(value, err: err || default_err, meta: ) end |
#Failure!(value = nil, err: nil, meta: {}, **_opts) ⇒ Object
Creates a Failure monad and immediately raises a FailFastError
72 73 74 75 76 77 78 |
# File 'lib/hati_command/cmd.rb', line 72 def Failure!(value = nil, err: nil, meta: {}, **_opts) # rubocop:disable Naming/MethodName default_error = self.class.command_config[:fail_fast] || self.class.command_config[:failure] error = err || default_error failure_obj = HatiCommand::Failure.new(value, err: error, meta: ) raise HatiCommand::Errors::FailFastError.new('Fail Fast Triggered', failure_obj: failure_obj) end |
#Success(value = nil, err: nil, meta: {}) ⇒ HatiCommand::Success
Creates a Success monad representing a successful operation
48 49 50 |
# File 'lib/hati_command/cmd.rb', line 48 def Success(value = nil, err: nil, meta: {}) # rubocop:disable Naming/MethodName HatiCommand::Success.new(value, err: err, meta: ) end |