Implement a key/value registry at env level
This commit is contained in:
parent
d845af60a3
commit
154ee8d534
@ -1,18 +1,27 @@
|
|||||||
module Producer
|
module Producer
|
||||||
module Core
|
module Core
|
||||||
class Env
|
class Env
|
||||||
attr_reader :input, :output
|
attr_reader :input, :output, :registry
|
||||||
attr_accessor :target
|
attr_accessor :target
|
||||||
|
|
||||||
def initialize(input: $stdin, output: $stdout)
|
def initialize(input: $stdin, output: $stdout, registry: {})
|
||||||
@input = input
|
@input = input
|
||||||
@output = output
|
@output = output
|
||||||
@target = nil
|
@target = nil
|
||||||
|
@registry = registry
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote
|
def remote
|
||||||
@remote ||= Remote.new(target)
|
@remote ||= Remote.new(target)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](key)
|
||||||
|
@registry[key]
|
||||||
|
end
|
||||||
|
|
||||||
|
def []=(key, value)
|
||||||
|
@registry[key] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,10 @@ module Producer::Core
|
|||||||
expect(env.target).not_to be
|
expect(env.target).not_to be
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'assigns an empty registry' do
|
||||||
|
expect(env.registry).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
context 'when input is given as argument' do
|
context 'when input is given as argument' do
|
||||||
let(:input) { double 'input' }
|
let(:input) { double 'input' }
|
||||||
subject(:env) { described_class.new(input: input) }
|
subject(:env) { described_class.new(input: input) }
|
||||||
@ -62,5 +66,20 @@ module Producer::Core
|
|||||||
expect(env.remote).to be env.remote
|
expect(env.remote).to be env.remote
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#[]' do
|
||||||
|
subject(:env) { Env.new(registry: { some_key: :some_value }) }
|
||||||
|
|
||||||
|
it 'returns the value indexed by given key from the registry' do
|
||||||
|
expect(env[:some_key]).to eq :some_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#[]=' do
|
||||||
|
it 'registers given value at given index in the registry' do
|
||||||
|
env[:some_key] = :some_value
|
||||||
|
expect(env[:some_key]).to eq :some_value
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user