Class: HaveAPI::Client::ActionState

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_blockObject (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

#progressObject (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

Returns:

  • (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

Returns:

  • (Boolean)


50
51
52
# File 'lib/haveapi/client/action_state.rb', line 50

def cancel?
  @cancel === true
end

#finished?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/haveapi/client/action_state.rb', line 30

def finished?
  @data[:finished] === true
end

#labelObject



22
23
24
# File 'lib/haveapi/client/action_state.rb', line 22

def label
  @data[:label]
end

#statusObject



26
27
28
# File 'lib/haveapi/client/action_state.rb', line 26

def status
  @data[:status] === true
end

#stopObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/haveapi/client/action_state.rb', line 60

def stop?
  !@stop.nil? && @stop
end