Class: Shamu::Services::ObservedRequest

Inherits:
Object
  • Object
show all
Includes:
Attributes
Defined in:
lib/shamu/services/observed_request.rb

Overview

Describes request that will be/has been performed by a service and the associated data properties.

Attributes collapse

Instance Method Summary collapse

Methods included from Attributes

#[], #as_json, #assign_attributes, association, associations, attribute, #attribute?, attributes, #initialize, #pretty_print, #set?, #slice, #to_attributes, #to_json

Instance Attribute Details

#cancel_reasonResult (readonly)

to be canceled.

Returns:

  • (Result)

    the result of a dependency that asked for the request



20
21
22
# File 'lib/shamu/services/observed_request.rb', line 20

def cancel_reason
  @cancel_reason
end

#requestRequest

request may be modified by the observers.

Returns:

  • (Request)

    the original request submitted to the service. The



16
# File 'lib/shamu/services/observed_request.rb', line 16

attribute :request

Instance Method Details

#cancel_requested?Boolean

canceled.

Returns:

  • (Boolean)

    true if an observer has asked the request to be



35
36
37
# File 'lib/shamu/services/observed_request.rb', line 35

def cancel_requested?
  !!cancel_reason
end

#complete(result, canceled) ⇒ Result

Mark the action as complete and run any #on_success or #on_fail callbacks.

processed.

Parameters:

  • result (Result)

    the result of the action. If valid success callbacks are invoked.

  • canceled (Boolean)

    true if the action was canceled and not

Returns:

  • (Result)

    the result of all the observed callbacks.



55
56
57
58
59
# File 'lib/shamu/services/observed_request.rb', line 55

def complete( result, canceled )
  invoke_callbacks( result, @on_cancel_blocks ) if canceled

  result
end

#on_canceled(&block) ⇒ Object

Execute block if the action was canceled by another observer. @yield(result)



42
43
44
45
# File 'lib/shamu/services/observed_request.rb', line 42

def on_canceled( &block )
  @on_cancel_blocks ||= []
  @on_cancel_blocks << block
end

#request_cancel(result = Result.new) ⇒ Result

Ask that the service cancel the request.

request was canceled.

Returns:

  • (Result)

    a nested result that should be reported for why the



29
30
31
# File 'lib/shamu/services/observed_request.rb', line 29

def request_cancel( result = Result.new )
  @cancel_reason = result
end