Class: Hubbado::Sequence::Runner::Dispatch
- Inherits:
-
Object
- Object
- Hubbado::Sequence::Runner::Dispatch
- Includes:
- Log::Dependency
- Defined in:
- lib/hubbado/sequence/runner.rb
Instance Attribute Summary collapse
-
#returned ⇒ Object
readonly
Returns the value of attribute returned.
-
#sequencer_class ⇒ Object
readonly
Returns the value of attribute sequencer_class.
Instance Method Summary collapse
-
#code ⇒ Object
Read-throughs to the wrapped Result.
- #ctx ⇒ Object
- #data ⇒ Object
- #enforce_safety_nets! ⇒ Object
- #handled? ⇒ Boolean
-
#initialize(sequencer_class, result) ⇒ Dispatch
constructor
A new instance of Dispatch.
- #log_unhandled ⇒ Object
- #message ⇒ Object
- #not_found ⇒ Object
-
#otherwise ⇒ Object
otherwise deliberately does not catch policy denials or not_found — those have their own required handlers.
- #policy_failed ⇒ Object
- #raise_failed ⇒ Object
- #raise_not_found ⇒ Object
-
#raise_policy_failed ⇒ Object
Raise the standard policy-denial exception.
- #step ⇒ Object
- #success ⇒ Object
- #successful_steps ⇒ Object
- #validation_failed ⇒ Object
Constructor Details
#initialize(sequencer_class, result) ⇒ Dispatch
Returns a new instance of Dispatch.
30 31 32 33 34 |
# File 'lib/hubbado/sequence/runner.rb', line 30 def initialize(sequencer_class, result) @sequencer_class = sequencer_class @result = result @handled = false end |
Instance Attribute Details
#returned ⇒ Object (readonly)
Returns the value of attribute returned.
28 29 30 |
# File 'lib/hubbado/sequence/runner.rb', line 28 def returned @returned end |
#sequencer_class ⇒ Object (readonly)
Returns the value of attribute sequencer_class.
28 29 30 |
# File 'lib/hubbado/sequence/runner.rb', line 28 def sequencer_class @sequencer_class end |
Instance Method Details
#code ⇒ Object
Read-throughs to the wrapped Result. Outcome blocks read these on the Dispatch object (the block argument) without hopping through an inner Result reference.
39 |
# File 'lib/hubbado/sequence/runner.rb', line 39 def code = @result.code |
#ctx ⇒ Object
44 |
# File 'lib/hubbado/sequence/runner.rb', line 44 def ctx = @result.ctx |
#data ⇒ Object
40 |
# File 'lib/hubbado/sequence/runner.rb', line 40 def data = @result.data |
#enforce_safety_nets! ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hubbado/sequence/runner.rb', line 105 def enforce_safety_nets! return if handled? log_unhandled case code when :forbidden then raise_policy_failed when :not_found then raise_not_found else raise_failed end end |
#handled? ⇒ Boolean
82 83 84 |
# File 'lib/hubbado/sequence/runner.rb', line 82 def handled? @result.success? || @handled end |
#log_unhandled ⇒ Object
117 118 119 |
# File 'lib/hubbado/sequence/runner.rb', line 117 def log_unhandled logger.error("Sequencer #{@sequencer_class.name} failed unhandled at #{step_label} (#{code}): #{steps_summary}") end |
#message ⇒ Object
42 |
# File 'lib/hubbado/sequence/runner.rb', line 42 def = @result. |
#not_found ⇒ Object
58 59 60 61 62 |
# File 'lib/hubbado/sequence/runner.rb', line 58 def not_found return unless code == :not_found execute { yield(@result.ctx) } logger.info("Sequencer #{@sequencer_class.name} not found at #{step_label}: #{steps_summary}") end |
#otherwise ⇒ Object
otherwise deliberately does not catch policy denials or not_found —those have their own required handlers.
72 73 74 75 76 77 78 79 80 |
# File 'lib/hubbado/sequence/runner.rb', line 72 def otherwise return if @result.success? return if code == :forbidden return if code == :not_found return if @handled execute { yield(@result.ctx) } logger.info("Sequencer #{@sequencer_class.name} failed at #{step_label} (#{code}): #{steps_summary}") end |
#policy_failed ⇒ Object
52 53 54 55 56 |
# File 'lib/hubbado/sequence/runner.rb', line 52 def policy_failed return unless code == :forbidden execute { yield(@result.ctx) } logger.info("Sequencer #{@sequencer_class.name} policy failed at #{step_label} (#{code}): #{steps_summary}") end |
#raise_failed ⇒ Object
101 102 103 |
# File 'lib/hubbado/sequence/runner.rb', line 101 def raise_failed raise Errors::Failed, "#{@sequencer_class.name} failed (#{code}): #{@result.}" end |
#raise_not_found ⇒ Object
97 98 99 |
# File 'lib/hubbado/sequence/runner.rb', line 97 def raise_not_found raise Errors::NotFound, "#{@sequencer_class.name} reported not_found" end |
#raise_policy_failed ⇒ Object
Raise the standard policy-denial exception. Available inside an outcome block (e.g. for callers that handle some policy reasons inline and want the framework’s standard escalation for the rest) and used internally by enforce_safety_nets! when no handler ran.
90 91 92 93 94 95 |
# File 'lib/hubbado/sequence/runner.rb', line 90 def raise_policy_failed raise Errors::Unauthorized.new( "#{@sequencer_class.name} denied: #{@result.}", @result ) end |
#step ⇒ Object
41 |
# File 'lib/hubbado/sequence/runner.rb', line 41 def step = @result.step |
#success ⇒ Object
46 47 48 49 50 |
# File 'lib/hubbado/sequence/runner.rb', line 46 def success return unless @result.success? execute { yield(@result.ctx) } logger.info("Sequencer #{@sequencer_class.name} succeeded: #{steps_summary}") end |
#successful_steps ⇒ Object
43 |
# File 'lib/hubbado/sequence/runner.rb', line 43 def successful_steps = @result.successful_steps |
#validation_failed ⇒ Object
64 65 66 67 68 |
# File 'lib/hubbado/sequence/runner.rb', line 64 def validation_failed return unless code == :validation_failed execute { yield(@result.ctx) } logger.info("Sequencer #{@sequencer_class.name} validation failed at #{step_label}: #{steps_summary}") end |