class Doable::Step
This class contains the actual work to be done
Attributes
name[R]
status[R]
success[R]
task[R]
Public Class Methods
new(context, options = {}, &block)
click to toggle source
@param options [Hash] @param block [Proc]
# File lib/doable/step.rb, line 8 def initialize(context, options = {}, &block) @context = context @success = false @status = :unattempted @task = block @name = options.key?(:name) ? options[:key] : block.to_s @rollback = nil end
Public Instance Methods
call(*args)
click to toggle source
Call our step, passing any arguments to the block (task) itself
# File lib/doable/step.rb, line 18 def call(*args) @status = :failed # first assume our attempt fails @context.instance_exec(*args, &@task) # try to execute the Step's task @success = true # we'll only get here if no exceptions were raised @status = :completed # if we're here, the Step is complete return self end
handled()
click to toggle source
Set the Step’s status to ‘handled’
# File lib/doable/step.rb, line 27 def handled @status = :handled @success = true # Might want to change this to false... end
retry(*args)
click to toggle source
Wrapper around call used for retrying a step. Recommended approach to retrying as this may be enhanced in the future.
# File lib/doable/step.rb, line 40 def retry(*args) call(*args) end
rollback(&block)
click to toggle source
Sets up a block to call when rolling back this step @return [Boolean]
# File lib/doable/step.rb, line 52 def rollback(&block) @rollback = block return true end
rollback!()
click to toggle source
Actually rollback this step
# File lib/doable/step.rb, line 68 def rollback! @context.instance_exec(&@rollback) @status = :rolledback @success = false end
rollbackable?()
click to toggle source
Query a step to see if it can be rolled back @return [Boolean]
# File lib/doable/step.rb, line 59 def rollbackable? if @rollback and [:completed, :handled, :failed].include?(@status) return true else return false end end
skip()
click to toggle source
allow skipping steps (needs to be called externally)
# File lib/doable/step.rb, line 45 def skip @status = :skipped @success = false end
successful?()
click to toggle source
Boolean way of requesting success @return [Boolean]
# File lib/doable/step.rb, line 34 def successful? return @success end