Class: Bricolage::Script
- Inherits:
-
Object
- Object
- Bricolage::Script
- Defined in:
- lib/bricolage/script.rb
Instance Method Summary collapse
- #bind(ctx, vars) ⇒ Object
-
#initialize ⇒ Script
constructor
A new instance of Script.
- #run ⇒ Object
- #run_explain ⇒ Object
- #source ⇒ Object
- #task(ds) ⇒ Object
Constructor Details
#initialize ⇒ Script
Returns a new instance of Script.
9 10 11 12 |
# File 'lib/bricolage/script.rb', line 9 def initialize @tasks = [] @in_task_block = false end |
Instance Method Details
#bind(ctx, vars) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/bricolage/script.rb', line 27 def bind(ctx, vars) raise "[BUG] unresolved variables given" unless vars.resolved? @tasks.each do |task| task.bind(ctx, vars) end end |
#run ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/bricolage/script.rb', line 44 def run result = nil @tasks.each do |task| result = task.run end result || JobResult.success end |
#run_explain ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bricolage/script.rb', line 52 def run_explain @tasks.each do |task| if task.respond_to?(:run_explain) task.run_explain else puts "-- task #{task.class} does not support explain; show source" puts task.source end end end |
#source ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/bricolage/script.rb', line 34 def source buf = StringIO.new first = true @tasks.each do |task| buf.puts unless first; first = false buf.puts task.source end buf.string end |
#task(ds) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bricolage/script.rb', line 14 def task(ds) raise FatalError, "nested task is not supported" if @in_task_block raise ParameterError, "no data source" unless ds @in_task_block = true begin task = ds.new_task yield task @tasks.push task ensure @in_task_block = false end end |