Class: CommandTower::Workflows::WorkflowResult
- Inherits:
-
Object
- Object
- CommandTower::Workflows::WorkflowResult
- Defined in:
- app/workflows/command_tower/workflows/workflow_result.rb
Constant Summary collapse
- STATUSES =
%i[success deferred failure].freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#response_effects ⇒ Object
readonly
Returns the value of attribute response_effects.
-
#retry_after ⇒ Object
readonly
Returns the value of attribute retry_after.
Class Method Summary collapse
- .deferred(reason:, retry_after:, payload: {}, http_status: :accepted, response_effects: nil, meta: {}) ⇒ Object
- .failure(errors:, http_status:, response_effects: nil, meta: {}) ⇒ Object
- .success(payload:, http_status: :ok, response_effects: nil, meta: {}) ⇒ Object
Instance Method Summary collapse
- #deferred? ⇒ Boolean
- #failure? ⇒ Boolean
-
#initialize(status:, payload:, errors:, http_status:, response_effects: nil, meta: {}, reason: nil, retry_after: nil) ⇒ WorkflowResult
constructor
A new instance of WorkflowResult.
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, payload:, errors:, http_status:, response_effects: nil, meta: {}, reason: nil, retry_after: nil) ⇒ WorkflowResult
Returns a new instance of WorkflowResult.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 10 def initialize(status:, payload:, errors:, http_status:, response_effects: nil, meta: {}, reason: nil, retry_after: nil) @status = status.to_sym raise ArgumentError, "invalid WorkflowResult status #{@status}" unless STATUSES.include?(@status) @payload = payload @errors = errors @http_status = http_status @response_effects = response_effects @meta = @reason = reason @retry_after = retry_after end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def errors @errors end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def http_status @http_status end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def @meta end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def payload @payload end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def reason @reason end |
#response_effects ⇒ Object (readonly)
Returns the value of attribute response_effects.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def response_effects @response_effects end |
#retry_after ⇒ Object (readonly)
Returns the value of attribute retry_after.
8 9 10 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8 def retry_after @retry_after end |
Class Method Details
.deferred(reason:, retry_after:, payload: {}, http_status: :accepted, response_effects: nil, meta: {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 44 def self.deferred(reason:, retry_after:, payload: {}, http_status: :accepted, response_effects: nil, meta: {}) new( status: :deferred, payload:, errors: [], http_status:, response_effects:, meta:, reason: reason.to_sym, retry_after: Integer(retry_after) ) end |
.failure(errors:, http_status:, response_effects: nil, meta: {}) ⇒ Object
40 41 42 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 40 def self.failure(errors:, http_status:, response_effects: nil, meta: {}) new(status: :failure, payload: nil, errors:, http_status:, response_effects:, meta:) end |
.success(payload:, http_status: :ok, response_effects: nil, meta: {}) ⇒ Object
36 37 38 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 36 def self.success(payload:, http_status: :ok, response_effects: nil, meta: {}) new(status: :success, payload:, errors: [], http_status:, response_effects:, meta:) end |
Instance Method Details
#deferred? ⇒ Boolean
28 29 30 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 28 def deferred? @status == :deferred end |
#failure? ⇒ Boolean
32 33 34 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 32 def failure? @status == :failure end |
#success? ⇒ Boolean
24 25 26 |
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 24 def success? @status == :success end |