class BehaveFun::TaskBuilderFactory

Attributes

tasks[R]

Public Class Methods

new(&block) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 5
def initialize(&block)
  @tasks = {}

  add_task_type BehaveFun::LeafTasks::Success
  add_task_type BehaveFun::LeafTasks::Failure
  add_task_type BehaveFun::LeafTasks::Wait
  add_task_type BehaveFun::Decorators::AlwaysSucceed
  add_task_type BehaveFun::Decorators::AlwaysFail
  add_task_type BehaveFun::Decorators::UntilSuccess
  add_task_type BehaveFun::Decorators::UntilFail
  add_task_type BehaveFun::Decorators::Invert
  add_task_type BehaveFun::Decorators::Repeat
  add_task_type BehaveFun::BranchTasks::Sequence
  add_task_type BehaveFun::BranchTasks::Selector
  add_task_type BehaveFun::BranchTasks::RandomSequence
  add_task_type BehaveFun::BranchTasks::RandomSelector
  add_task_type BehaveFun::BranchTasks::DynamicGuardSelector

  instance_eval(&block) if block_given?
end

Public Instance Methods

add_lambda_task_type(task_name, &block) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 30
def add_lambda_task_type(task_name, &block)
  type = Class.new(Task) do
    def name
      task_name
    end

    define_method(:execute, &block)
  end
  tasks[task_name.to_sym] = type
end
add_task_type(type, name: type.task_name) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 26
def add_task_type(type, name: type.task_name)
  tasks[name.to_sym] = type
end
as_json(tree) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 73
def as_json(tree)
  tree.as_json
end
build_task(&block) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 41
def build_task(&block)
  task = build_tree(&block).root
  task.control = nil
  task
end
build_task_from_hash(hash) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 53
def build_task_from_hash(hash)
  hash = hash.deep_symbolize_keys
  tree = build_tree do
    build_from_hash(hash)
  end
  tree.root
end
build_tree(&block) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 47
def build_tree(&block)
  builder = Builder.new(self, Tree.new)
  builder.instance_eval(&block)
  builder.control
end
build_tree_from_hash(hash) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 61
def build_tree_from_hash(hash)
  hash = hash.deep_symbolize_keys
  build_tree do
    build_from_hash(hash[:root])
  end
end
build_tree_from_json(json) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 68
def build_tree_from_json(json)
  hash = ActiveSupport::JSON.decode(json).deep_symbolize_keys
  build_tree_from_hash(hash)
end
name() click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 32
def name
  task_name
end
to_json(tree) click to toggle source
# File lib/behave_fun/task_builder_factory.rb, line 77
def to_json(tree)
  ActiveSupport::JSON.encode(as_json(tree))
end