Attach our env to the worker from the CLI
This commit is contained in:
parent
024ab7eba0
commit
7cffa34442
@ -19,21 +19,26 @@ module Producer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :arguments, :stdout, :recipe
|
attr_reader :arguments, :stdout, :env, :recipe
|
||||||
|
|
||||||
def initialize(arguments, stdout: $stdout)
|
def initialize(args, stdout: $stdout)
|
||||||
raise ArgumentError unless arguments.any?
|
@arguments = args
|
||||||
@arguments = arguments
|
|
||||||
@stdout = stdout
|
@stdout = stdout
|
||||||
|
@env = Env.new(output: stdout)
|
||||||
|
raise ArgumentError unless arguments.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(worker: Worker.new)
|
def run(worker: build_worker)
|
||||||
load_recipe
|
load_recipe
|
||||||
worker.process recipe.tasks
|
worker.process recipe.tasks
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_recipe
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
module Producer
|
module Producer
|
||||||
module Core
|
module Core
|
||||||
class Worker
|
class Worker
|
||||||
|
attr_accessor :env
|
||||||
|
|
||||||
|
def initialize(env)
|
||||||
|
@env = env
|
||||||
|
end
|
||||||
|
|
||||||
def process(tasks)
|
def process(tasks)
|
||||||
tasks.each { |t| process_task t }
|
tasks.each { |t| process_task t }
|
||||||
end
|
end
|
||||||
|
@ -44,10 +44,16 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
subject(:cli) { CLI.new(arguments) }
|
it 'assigns the env with CLI output' do
|
||||||
|
expect(cli.env.output).to be stdout
|
||||||
|
end
|
||||||
|
|
||||||
it 'assigns $stdout as the default standard output' do
|
context 'without options' do
|
||||||
expect(cli.stdout).to be $stdout
|
subject(:cli) { CLI.new(arguments) }
|
||||||
|
|
||||||
|
it 'assigns $stdout as the default standard output' do
|
||||||
|
expect(cli.stdout).to be $stdout
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without arguments' do
|
context 'without arguments' do
|
||||||
@ -84,10 +90,16 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#env' do
|
||||||
|
it 'returns an env' do
|
||||||
|
expect(cli.env).to be_an Env
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#load_recipe' do
|
describe '#load_recipe' do
|
||||||
it 'evaluates the recipe file with an env' do
|
it 'evaluates the recipe file with the CLI env' do
|
||||||
expect(Recipe)
|
expect(Recipe)
|
||||||
.to receive(:evaluate_from_file).with(recipe_file, kind_of(Env))
|
.to receive(:evaluate_from_file).with(recipe_file, cli.env)
|
||||||
cli.load_recipe
|
cli.load_recipe
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,5 +108,15 @@ module Producer::Core
|
|||||||
expect(cli.recipe.tasks.count).to be 2
|
expect(cli.recipe.tasks.count).to be 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#build_worker' do
|
||||||
|
it 'returns a worker' do
|
||||||
|
expect(cli.build_worker).to be_a Worker
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns the CLI env' do
|
||||||
|
expect(cli.build_worker.env).to eq cli.env
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
|||||||
|
|
||||||
module Producer::Core
|
module Producer::Core
|
||||||
describe Worker do
|
describe Worker do
|
||||||
subject(:worker) { described_class.new }
|
let(:env) { Env.new }
|
||||||
|
subject(:worker) { described_class.new(env) }
|
||||||
|
|
||||||
describe '#process' do
|
describe '#process' do
|
||||||
it 'processes each task' do
|
it 'processes each task' do
|
||||||
@ -31,5 +32,11 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#env' do
|
||||||
|
it 'returns the assigned env' do
|
||||||
|
expect(worker.env).to be env
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user