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 |
# File 'lib/haveapi/client/action_state.rb', line 16 def initialize(response) @data = response.response @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
34 35 36 |
# File 'lib/haveapi/client/action_state.rb', line 34 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.
41 42 43 44 45 46 47 48 |
# File 'lib/haveapi/client/action_state.rb', line 41 def cancel(&block) unless can_cancel? raise "action ##{@data[:id]} (#{label}) cannot be cancelled" end @cancel = true @cancel_block = block end |
#cancel? ⇒ Boolean
50 51 52 |
# File 'lib/haveapi/client/action_state.rb', line 50 def cancel? @cancel === true end |
#finished? ⇒ Boolean
30 31 32 |
# File 'lib/haveapi/client/action_state.rb', line 30 def finished? @data[:finished] === true end |
#label ⇒ Object
22 23 24 |
# File 'lib/haveapi/client/action_state.rb', line 22 def label @data[:label] end |
#status ⇒ Object
26 27 28 |
# File 'lib/haveapi/client/action_state.rb', line 26 def status @data[:status] === true end |
#stop ⇒ Object
Stop monitoring the action’s state, the call from Action.wait_for_completion will return.
56 57 58 |
# File 'lib/haveapi/client/action_state.rb', line 56 def stop @stop = true end |
#stop? ⇒ Boolean
60 61 62 |
# File 'lib/haveapi/client/action_state.rb', line 60 def stop? !@stop.nil? && @stop end |