Class: CMDx::Fault
- Inherits:
-
Error
- Object
- Error
- CMDx::Fault
- Extended by:
- Forwardable
- Defined in:
- lib/cmdx/faults.rb
Overview
Base fault class for handling task execution failures and interruptions.
Faults represent error conditions that occur during task execution, providing a structured way to handle and categorize different types of failures. Each fault contains a reference to the result object that caused the fault.
Instance Attribute Summary collapse
-
#result ⇒ Result
readonly
Returns the result that caused this fault.
Class Method Summary collapse
-
.for?(*tasks) ⇒ Class
Create a fault class that matches specific task types.
-
.matches?(&block) ⇒ Class
Create a fault class that matches based on a custom block.
Instance Method Summary collapse
-
#initialize(result) ⇒ Fault
constructor
Initialize a new fault with the given result.
Constructor Details
#initialize(result) ⇒ Fault
Initialize a new fault with the given result.
37 38 39 40 41 |
# File 'lib/cmdx/faults.rb', line 37 def initialize(result) @result = result super(result.reason) end |
Instance Attribute Details
#result ⇒ Result (readonly)
Returns the result that caused this fault.
22 23 24 |
# File 'lib/cmdx/faults.rb', line 22 def result @result end |
Class Method Details
.for?(*tasks) ⇒ Class
Create a fault class that matches specific task types.
56 57 58 59 60 61 62 63 64 |
# File 'lib/cmdx/faults.rb', line 56 def for?(*tasks) temp_fault = Class.new(self) do def self.===(other) other.is_a?(superclass) && @tasks.any? { |task| other.task.is_a?(task) } end end temp_fault.tap { |c| c.instance_variable_set(:@tasks, tasks) } end |
.matches?(&block) ⇒ Class
Create a fault class that matches based on a custom block.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cmdx/faults.rb', line 79 def matches?(&block) raise ArgumentError, "block required" unless block_given? temp_fault = Class.new(self) do def self.===(other) other.is_a?(superclass) && @block.call(other) end end temp_fault.tap { |c| c.instance_variable_set(:@block, block) } end |