Class: HaveAPI::Client::ActionState
- Inherits:
-
Object
- Object
- HaveAPI::Client::ActionState
- Defined in:
- lib/haveapi/client/action_state.rb
Overview
Represents action's state as returned from API resource ActionState.Show/Poll.
Defined Under Namespace
Classes: Progress
Instance Attribute Summary collapse
-
#cancel_block ⇒ Object
readonly
Returns the value of attribute cancel_block.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #can_cancel? ⇒ Boolean
-
#cancel(&block) ⇒ Object
Stop monitoring the action's state and attempt to cancel it.
- #cancel? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(response) ⇒ ActionState
constructor
A new instance of ActionState.
- #label ⇒ Object
- #status ⇒ Object
-
#stop ⇒ Object
Stop monitoring the action's state, the call from Action.wait_for_completion will return.
- #stop? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ ActionState
Returns a new instance of ActionState.
16 17 18 19 20 21 |
# File 'lib/haveapi/client/action_state.rb', line 16 def initialize(response) @data = response.response @client = response.action.client @progress = Progress.new(@data[:current], @data[:total], @data[:unit]) end |
Instance Attribute Details
#cancel_block ⇒ Object (readonly)
Returns the value of attribute cancel_block.
14 15 16 |
# File 'lib/haveapi/client/action_state.rb', line 14 def cancel_block @cancel_block end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
14 15 16 |
# File 'lib/haveapi/client/action_state.rb', line 14 def progress @progress end |
Instance Method Details
#can_cancel? ⇒ Boolean
35 36 37 |
# File 'lib/haveapi/client/action_state.rb', line 35 def can_cancel? @data[:can_cancel] === true end |
#cancel(&block) ⇒ Object
Stop monitoring the action's state and attempt to cancel it. The block
is given to Action.wait_for_completion for the cancel operation. The block
is used only if the cancel operation is blocking.
42 43 44 45 46 47 48 49 |
# File 'lib/haveapi/client/action_state.rb', line 42 def cancel(&block) unless can_cancel? raise @client.('errors.uncancelable_action', id: @data[:id]) end @cancel = true @cancel_block = block end |
#cancel? ⇒ Boolean
51 52 53 |
# File 'lib/haveapi/client/action_state.rb', line 51 def cancel? @cancel === true end |
#finished? ⇒ Boolean
31 32 33 |
# File 'lib/haveapi/client/action_state.rb', line 31 def finished? @data[:finished] === true end |
#label ⇒ Object
23 24 25 |
# File 'lib/haveapi/client/action_state.rb', line 23 def label @data[:label] end |
#status ⇒ Object
27 28 29 |
# File 'lib/haveapi/client/action_state.rb', line 27 def status @data[:status] === true end |
#stop ⇒ Object
Stop monitoring the action's state, the call from Action.wait_for_completion will return.
57 58 59 |
# File 'lib/haveapi/client/action_state.rb', line 57 def stop @stop = true end |
#stop? ⇒ Boolean
61 62 63 |
# File 'lib/haveapi/client/action_state.rb', line 61 def stop? !@stop.nil? && @stop end |