diff --git a/features/registry.feature b/features/registry.feature index f4f2bb6..8802624 100644 --- a/features/registry.feature +++ b/features/registry.feature @@ -24,3 +24,13 @@ Feature: key/value registry """ When I successfully execute the recipe Then the output must contain "some_value" + + Scenario: `get' keyword fetches a value from a condition + Given a recipe with: + """ + set :some_key, 'some_value' + + task(:ok) { condition { get :some_key }; echo get :some_key } + """ + When I successfully execute the recipe + Then the output must contain "some_value" diff --git a/lib/producer/core/condition.rb b/lib/producer/core/condition.rb index 0270b8b..5d9fb66 100644 --- a/lib/producer/core/condition.rb +++ b/lib/producer/core/condition.rb @@ -29,6 +29,9 @@ module Producer end end + extend Forwardable + def_delegators :@env, :get + define_test :`, Tests::ShellCommandStatus define_test :sh, Tests::ShellCommandStatus define_test :file_contains, Tests::FileContains diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index e4bed73..30a64dd 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -20,6 +20,7 @@ module Producer def [](key) @registry[key] end + alias get [] def []=(key, value) @registry[key] = value diff --git a/spec/producer/core/condition_spec.rb b/spec/producer/core/condition_spec.rb index f39e3e2..95498f3 100644 --- a/spec/producer/core/condition_spec.rb +++ b/spec/producer/core/condition_spec.rb @@ -173,5 +173,14 @@ module Producer::Core end end end + + describe '#get' do + let(:env) { Env.new } + + it 'delegates to env registry' do + expect(env).to receive(:get).with :some_key + described_class.evaluate(env, []) { get :some_key } + end + end end end