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