Class: Taskinator::Builder
- Inherits:
-
Object
- Object
- Taskinator::Builder
- Defined in:
- lib/taskinator/builder.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#builder_options ⇒ Object
readonly
Returns the value of attribute builder_options.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Instance Method Summary collapse
-
#concurrent(complete_on = CompleteOn::Default, options = {}, &block) ⇒ Object
defines a sub process of tasks which are executed concurrently.
-
#for_each(method, options = {}, &block) ⇒ Object
(also: #transform)
dynamically defines tasks, using the given @iterator method the definition will be evaluated for each yielded item.
-
#initialize(process, definition, *args) ⇒ Builder
constructor
A new instance of Builder.
-
#job(job, options = {}) ⇒ Object
defines a task which executes the given @job which is expected to implement a perform method either as a class or instance method.
- #option?(key, &block) ⇒ Boolean
-
#sequential(options = {}, &block) ⇒ Object
defines a sub process of tasks which are executed sequentially.
-
#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.
-
#task(method, options = {}) ⇒ Object
defines a task which executes the given @method.
Constructor Details
#initialize(process, definition, *args) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 14 15 |
# File 'lib/taskinator/builder.rb', line 9 def initialize(process, definition, *args) @process = process @definition = definition @builder_options = args.last.is_a?(Hash) ? args.pop : {} @args = args @executor = Taskinator::Executor.new(@definition) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/taskinator/builder.rb', line 6 def args @args end |
#builder_options ⇒ Object (readonly)
Returns the value of attribute builder_options.
7 8 9 |
# File 'lib/taskinator/builder.rb', line 7 def @builder_options end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/taskinator/builder.rb', line 5 def definition @definition end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
4 5 6 |
# File 'lib/taskinator/builder.rb', line 4 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
33 34 35 36 37 38 39 40 41 |
# File 'lib/taskinator/builder.rb', line 33 def concurrent(complete_on=CompleteOn::Default, ={}, &block) raise ArgumentError, 'block' unless block_given? sub_process = Process.define_concurrent_process_for(@definition, complete_on, ) task = define_sub_process_task(@process, sub_process, ) Builder.new(sub_process, @definition, *@args).instance_eval(&block) @process.tasks << task if sub_process.tasks.any? nil end |
#for_each(method, options = {}, &block) ⇒ Object Also known as: transform
dynamically defines tasks, using the given @iterator method the definition will be evaluated for each yielded item
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/taskinator/builder.rb', line 45 def for_each(method, ={}, &block) raise ArgumentError, 'method' if method.nil? raise NoMethodError, method unless @executor.respond_to?(method) raise ArgumentError, 'block' unless block_given? # # `for_each` is an exception, since it invokes the definition # in order to yield elements to the builder, and any options passed # are included with the builder options # method_args = .any? ? [*@args, ] : @args @executor.send(method, *method_args) do |*args| Builder.new(@process, @definition, *args).instance_eval(&block) end nil end |
#job(job, options = {}) ⇒ Object
defines a task which executes the given @job which is expected to implement a perform method either as a class or instance method
75 76 77 78 79 80 81 |
# File 'lib/taskinator/builder.rb', line 75 def job(job, ={}) raise ArgumentError, 'job' if job.nil? raise ArgumentError, 'job' unless job.methods.include?(:perform) || job.instance_methods.include?(:perform) define_job_task(@process, job, @args, ) nil end |
#option?(key, &block) ⇒ Boolean
17 18 19 |
# File 'lib/taskinator/builder.rb', line 17 def option?(key, &block) yield if [key] end |
#sequential(options = {}, &block) ⇒ Object
defines a sub process of tasks which are executed sequentially
22 23 24 25 26 27 28 29 30 |
# File 'lib/taskinator/builder.rb', line 22 def sequential(={}, &block) raise ArgumentError, 'block' unless block_given? sub_process = Process.define_sequential_process_for(@definition, ) task = define_sub_process_task(@process, sub_process, ) Builder.new(sub_process, @definition, *@args).instance_eval(&block) @process.tasks << task if sub_process.tasks.any? nil 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
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/taskinator/builder.rb', line 90 def sub_process(definition, ={}) raise ArgumentError, 'definition' if definition.nil? raise ArgumentError, "#{definition.name} does not extend the #{Definition.name} module" unless definition.kind_of?(Definition) sub_process = definition.create_sub_process(*@args, ()) task = define_sub_process_task(@process, sub_process, ) Builder.new(sub_process, definition, *@args) @process.tasks << task if sub_process.tasks.any? nil end |
#task(method, options = {}) ⇒ Object
defines a task which executes the given @method
65 66 67 68 69 70 71 |
# File 'lib/taskinator/builder.rb', line 65 def task(method, ={}) raise ArgumentError, 'method' if method.nil? raise NoMethodError, method unless @executor.respond_to?(method) define_step_task(@process, method, @args, ) nil end |