Class: CommandTower::Workflows::WorkflowResult

Inherits:
Object
  • Object
show all
Defined in:
app/workflows/command_tower/workflows/workflow_result.rb

Constant Summary collapse

STATUSES =
%i[success deferred failure].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, payload:, errors:, http_status:, response_effects: nil, meta: {}, reason: nil, retry_after: nil) ⇒ WorkflowResult

Returns a new instance of WorkflowResult.

Raises:

  • (ArgumentError)


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 = meta
  @reason = reason
  @retry_after = retry_after
end

Instance Attribute Details

#errorsObject (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_statusObject (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

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 8

def meta
  @meta
end

#payloadObject (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

#reasonObject (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_effectsObject (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_afterObject (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

Returns:

  • (Boolean)


28
29
30
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 28

def deferred?
  @status == :deferred
end

#failure?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 32

def failure?
  @status == :failure
end

#success?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/workflows/command_tower/workflows/workflow_result.rb', line 24

def success?
  @status == :success
end