Class: Taskinator::Definition::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/taskinator/definition/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process, definition, args) ⇒ Builder

Returns a new instance of Builder.



9
10
11
12
13
14
# File 'lib/taskinator/definition/builder.rb', line 9

def initialize(process, definition, args)
  @process = process
  @definition = definition
  @args = args
  @executor = Taskinator::Executor.new(@definition)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'lib/taskinator/definition/builder.rb', line 7

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



6
7
8
# File 'lib/taskinator/definition/builder.rb', line 6

def definition
  @definition
end

#processObject (readonly)

Returns the value of attribute process.



5
6
7
# File 'lib/taskinator/definition/builder.rb', line 5

def process
  @process
end

Instance Method Details

#concurrent(complete_on = CompleteOn::Default, options = {}, &block) ⇒ Object

defines a sub process of tasks which are executed concurrently

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/taskinator/definition/builder.rb', line 25

def concurrent(complete_on=CompleteOn::Default, options={}, &block)
  raise ArgumentError, 'block' unless block_given?

  sub_process = Process.define_concurrent_process_for(@definition, complete_on, options)
  Builder.new(define_sub_process_task(@process, sub_process, options), @definition, @args).instance_eval(&block)
end

#for_each(iterator_method, options = {}, &block) ⇒ Object

dynamically defines tasks, using the given @iterator method the definition will be evaluated for each yielded item

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
# File 'lib/taskinator/definition/builder.rb', line 34

def for_each(iterator_method, options={}, &block)
  raise ArgumentError, 'iterator_method' if iterator_method.nil?
  raise NoMethodError, iterator_method unless @executor.respond_to?(iterator_method)
  raise ArgumentError, 'block' unless block_given?

  @executor.send(iterator_method, *@args) do |*args|
    Builder.new(@process, @definition, args).instance_eval(&block)
  end
end

#sequential(options = {}, &block) ⇒ Object

defines a sub process of tasks which are executed sequentially

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/taskinator/definition/builder.rb', line 17

def sequential(options={}, &block)
  raise ArgumentError, 'block' unless block_given?

  sub_process = Process.define_sequential_process_for(@definition, options)
  Builder.new(define_sub_process_task(@process, sub_process, options), @definition, @args).instance_eval(&block)
end

#sub_process(definition, options = {}) ⇒ Object

defines a sub process task, for the given @definition the definition specified must have input compatible arguments to the current definition

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
# File 'lib/taskinator/definition/builder.rb', line 55

def sub_process(definition, options={})
  raise ArgumentError, 'definition' if definition.nil?
  raise ArgumentError, "#{definition.name} does not extend the #{Definition.name} module" unless definition.kind_of?(Definition)

  # TODO: decide whether the sub process to dynamically receive arguments

  sub_process = definition.create_process(*@args)
  Builder.new(define_sub_process_task(@process, sub_process, options), definition, @args)
end

#task(method, options = {}) ⇒ Object

defines a task which executes the given @method

Raises:

  • (ArgumentError)


45
46
47
48
49
50
# File 'lib/taskinator/definition/builder.rb', line 45

def task(method, options={})
  raise ArgumentError, 'method' if method.nil?
  raise NoMethodError, method unless @executor.respond_to?(method)

  define_step_task(@process, method, @args, options)
end