class Shamu::Services::ObservedRequest
Describes request that will be/has been performed by a service and the associated data properties.
Attributes
@return [Result] the result of a dependency that asked for the request to be canceled.
Public Instance Methods
@return [Boolean] true if an observer has asked the request to be canceled.
# File lib/shamu/services/observed_request.rb, line 35 def cancel_requested? !!cancel_reason end
Mark the action as complete and run any {#on_success} or #{on_fail} callbacks.
@param [Result] result the result of the action. If valid success callbacks are invoked. @param [Boolean] canceled true if the action was canceled and not processed.
@return [Result] the result of all the observed callbacks.
# File lib/shamu/services/observed_request.rb, line 55 def complete( result, canceled ) invoke_callbacks( result, @on_cancel_blocks ) if canceled result end
Execute block if the action was canceled by another observer. @yield(result) @yieldresult [Result]
# File lib/shamu/services/observed_request.rb, line 42 def on_canceled( &block ) @on_cancel_blocks ||= [] @on_cancel_blocks << block end
Ask that the service cancel the request.
@return [Result] a nested result that should be reported for why the request was canceled.
# File lib/shamu/services/observed_request.rb, line 29 def request_cancel( result = Result.new ) @cancel_reason = result end
Private Instance Methods
# File lib/shamu/services/observed_request.rb, line 63 def invoke_callbacks( result, callbacks ) return unless callbacks.present? callbacks.each do |callback| nested = callback.call( result ) result.join( nested ) if nested end result end