Attach our env to the worker from the CLI

This commit is contained in:
Thibault Jouan
2014-05-19 23:02:23 +00:00
parent 024ab7eba0
commit 7cffa34442
4 changed files with 52 additions and 12 deletions

View File

@@ -19,21 +19,26 @@ module Producer
end
end
attr_reader :arguments, :stdout, :recipe
attr_reader :arguments, :stdout, :env, :recipe
def initialize(arguments, stdout: $stdout)
raise ArgumentError unless arguments.any?
@arguments = arguments
def initialize(args, stdout: $stdout)
@arguments = args
@stdout = stdout
@env = Env.new(output: stdout)
raise ArgumentError unless arguments.any?
end
def run(worker: Worker.new)
def run(worker: build_worker)
load_recipe
worker.process recipe.tasks
end
def load_recipe
@recipe = Recipe.evaluate_from_file(@arguments.first, Env.new)
@recipe = Recipe.evaluate_from_file(@arguments.first, env)
end
def build_worker
Worker.new(env)
end
end
end

View File

@@ -1,6 +1,12 @@
module Producer
module Core
class Worker
attr_accessor :env
def initialize(env)
@env = env
end
def process(tasks)
tasks.each { |t| process_task t }
end