diff --git a/README.md b/README.md index e51c776..322f150 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ The following types are supported: ### Groups -Groups give you more flexibility to define when variables are needed. +Groups give you more flexibility to define when variables are needed. It's similar to groups in a Gemfile: ```ruby @@ -103,6 +103,10 @@ variable :FORCE_SSL, :boolean group :production do variable :SECRET_KEY_BASE end + +group :development, :staging do + variable :DEV_KEY +end ``` ```ruby @@ -142,7 +146,7 @@ variable :PORT, :integer, default: proc {|envied| envied.FORCE_SSL ? 443 : 80 } ``` Please remember that ENVied only **reads** from ENV; it doesn't mutate ENV. -Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set. +Don't let setting a default for, say `RAILS_ENV`, give you the impression that `ENV['RAILS_ENV']` is set. As a rule of thumb you should only use defaults: * for local development * for ENV-variables that are solely used by your application (i.e. for `ENV['STAFF_EMAILS']`, not for `ENV['RAILS_ENV']`) diff --git a/lib/envied/configuration.rb b/lib/envied/configuration.rb index c360ea2..3191813 100644 --- a/lib/envied/configuration.rb +++ b/lib/envied/configuration.rb @@ -45,9 +45,11 @@ def variable(name, *args) variables << ENVied::Variable.new(name, type, options) end - def group(name, &block) - @current_group = name.to_sym - yield + def group(*names, &block) + names.each do |name| + @current_group = name.to_sym + yield + end ensure @current_group = nil end diff --git a/spec/envied_spec.rb b/spec/envied_spec.rb index b59d9e4..2fc3226 100644 --- a/spec/envied_spec.rb +++ b/spec/envied_spec.rb @@ -283,6 +283,28 @@ def envied_require(*args) end end + context 'a variable in multiple groups' do + before do + configure do + variable :moar + + group :foo, :moo do + variable :bar + end + end.and_no_ENV + end + + it 'is required when requiring any of the groups' do + expect { + envied_require(:foo) + }.to raise_error(/bar/) + + expect { + envied_require(:moo) + }.to raise_error(/bar/) + end + end + describe 'Hashable' do before do configure do