class BehaveFun::Task

Attributes

children[R]
context[R]
control[RW]
guard[RW]
params[RW]
status[R]

Public Class Methods

new(params = {}) click to toggle source
# File lib/behave_fun/task.rb, line 8
def initialize(params = {})
  self.params = params
  @children = []
  @status = :fresh
end
task_name() click to toggle source
# File lib/behave_fun/task.rb, line 14
def self.task_name
  name.demodulize.underscore
end

Public Instance Methods

add_child(task) click to toggle source
# File lib/behave_fun/task.rb, line 92
def add_child(task)
  @children << task
  task.control = self
end
cancel() click to toggle source
# File lib/behave_fun/task.rb, line 38
def cancel
  @status = :cancelled
  children.each { |child| child.cancel }
end
cancelled?() click to toggle source
# File lib/behave_fun/task.rb, line 59
def cancelled?
  @status == :cancelled
end
child_fail() click to toggle source
# File lib/behave_fun/task.rb, line 88
def child_fail; end
child_running() click to toggle source
# File lib/behave_fun/task.rb, line 90
def child_running; end
child_success() click to toggle source
# File lib/behave_fun/task.rb, line 86
def child_success; end
context=(context) click to toggle source
# File lib/behave_fun/task.rb, line 18
def context=(context)
  @context = context
  children.each { _1.context = context }
end
dup() click to toggle source
# File lib/behave_fun/task.rb, line 119
def dup
  cloned = self.class.new(params)
  children.each { cloned.add_child(_1.dup) }
  cloned
end
ended?() click to toggle source
# File lib/behave_fun/task.rb, line 63
def ended?
  succeeded? || failed? || cancelled?
end
execute() click to toggle source
# File lib/behave_fun/task.rb, line 84
def execute; end
fail() click to toggle source
# File lib/behave_fun/task.rb, line 33
def fail
  @status = :failed
  control.child_fail if control
end
failed?() click to toggle source
# File lib/behave_fun/task.rb, line 55
def failed?
  @status == :failed
end
fresh?() click to toggle source
# File lib/behave_fun/task.rb, line 43
def fresh?
  @status == :fresh
end
guard_passed?() click to toggle source
# File lib/behave_fun/task.rb, line 67
def guard_passed?
  return true unless guard

  guard.context = context
  guard.reset
  guard.run

  case guard.status
  when :succeeded then true
  when :failed    then false
  else
    raise Error, 'Guard should finish in one step'
  end
end
reset() click to toggle source
# File lib/behave_fun/task.rb, line 113
def reset
  cancel
  @status = :fresh
  children.each { |child| child.reset }
end
run() click to toggle source
# File lib/behave_fun/task.rb, line 97
def run
  raise Error, 'Cannot run ended task' if ended?
  if fresh?
    if guard_passed?
      start
      running
      execute
    else
      fail
    end
  else
    running
    execute
  end
end
running() click to toggle source
# File lib/behave_fun/task.rb, line 23
def running
  @status = :running
  control.child_running if control
end
running?() click to toggle source
# File lib/behave_fun/task.rb, line 47
def running?
  @status == :running
end
start() click to toggle source
# File lib/behave_fun/task.rb, line 82
def start; end
succeeded?() click to toggle source
# File lib/behave_fun/task.rb, line 51
def succeeded?
  @status == :succeeded
end
success() click to toggle source
# File lib/behave_fun/task.rb, line 28
def success
  @status = :succeeded
  control.child_success if control
end