Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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']`)
Expand Down
8 changes: 5 additions & 3 deletions lib/envied/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/envied_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down