Class: Servus::Support::Rescuer::BlockContext Private
- Inherits:
-
Object
- Object
- Servus::Support::Rescuer::BlockContext
- Defined in:
- lib/servus/support/rescuer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides success/failure methods to rescue_from blocks.
This context is used when a rescue_from block is executed. It provides the same success() and failure() methods available in service call methods, allowing blocks to create appropriate Response objects.
Instance Attribute Summary collapse
-
#result ⇒ Servus::Support::Response?
readonly
private
The response created by success() or failure().
Instance Method Summary collapse
-
#failure(message = nil, type: Servus::Support::Errors::ServiceError) ⇒ Servus::Support::Response
private
Creates a failure response.
-
#initialize ⇒ BlockContext
constructor
private
A new instance of BlockContext.
-
#success(data = nil) ⇒ Servus::Support::Response
private
Creates a success response.
Constructor Details
#initialize ⇒ BlockContext
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of BlockContext.
40 41 42 |
# File 'lib/servus/support/rescuer.rb', line 40 def initialize @result = nil end |
Instance Attribute Details
#result ⇒ Servus::Support::Response? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The response created by success() or failure().
82 83 84 |
# File 'lib/servus/support/rescuer.rb', line 82 def result @result end |
Instance Method Details
#failure(message = nil, type: Servus::Support::Errors::ServiceError) ⇒ Servus::Support::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a failure response.
Use this in rescue_from blocks to convert exceptions into business failures with custom messages and error types.
73 74 75 76 |
# File 'lib/servus/support/rescuer.rb', line 73 def failure( = nil, type: Servus::Support::Errors::ServiceError) error = type.new() @result = Response.new(false, nil, error) end |
#success(data = nil) ⇒ Servus::Support::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a success response.
Use this in rescue_from blocks to recover from exceptions and return successful results despite the error being raised.
56 57 58 |
# File 'lib/servus/support/rescuer.rb', line 56 def success(data = nil) @result = Response.new(true, data, nil) end |