Class: R10K::Util::Attempt Private

Inherits:
Object
  • Object
show all
Includes:
Logging, Setopts
Defined in:
lib/r10k/util/attempt.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Attempt a series of dependent nested tasks and cleanly handle errors.

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initialize(initial, opts = {}) ⇒ Attempt

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Attempt.



21
22
23
24
25
26
# File 'lib/r10k/util/attempt.rb', line 21

def initialize(initial, opts = {})
  @initial = initial
  @tries = []
  @status = :notrun
  setopts(opts, {:trace => :self})
end

Instance Attribute Details

#statusObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/r10k/util/attempt.rb', line 19

def status
  @status
end

Instance Method Details

#ok?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


52
53
54
# File 'lib/r10k/util/attempt.rb', line 52

def ok?
  @status == :ok
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

determine the structure of the ret

Run this attempt to completion.

Returns:

  • (Object)

    The aggregate result of all work performed.



32
33
34
35
36
37
# File 'lib/r10k/util/attempt.rb', line 32

def run
  @status = :running
  result = apply(@initial, @tries)
  @status = :ok if @status == :running
  result
end

#try {|The| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add another action to take for this attempt

Yield Parameters:

  • The (Object)

    result of the previous action.

Yield Returns:

  • (Object, Array<Object>, NilClass)

    The result of this action. If the value is an object, it will be passed to the next attempt. If the value is an Array then each element will be individually passed to the next try. If the value is false or nil then no further action will be taken.



47
48
49
50
# File 'lib/r10k/util/attempt.rb', line 47

def try(&block)
  @tries << block
  self
end