Skip to content

Commit

Permalink
Honour APP_ENV as an alternative to RODBOT_ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
svoop committed Feb 12, 2024
1 parent 56f67eb commit 4f48037
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Changes
* Adhere to plugin file layout suggestions
* Support Ruby 3.3
* Honor `APP_ENV` as an alternative to `RODBOT_ENV`

## 0.4.3

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ Rodbot.env.production? # => true
Rodbot.env.development? # => false
```

You can use the more generic alternative `APP_ENV` as well, however, if `RODBOT_ENV` is defined, it takes precedence over `APP_ENV`.

## Credentials

In order not to commit secrets to repositories or environment variables, Rodbot bundles the [dry-credentials](https://rubygems.org/gems/dry-credentials) gem and exposes it via the `rodbot credentials` CLI command. The secrets are then available in your code like `Rodbot.credentials.my_secret` and the encrypted files are written to `config/credentials`.
Expand Down
2 changes: 1 addition & 1 deletion lib/rodbot/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(root: nil)
@root = root ? Pathname(root).realpath : Pathname.pwd
@tmp = @root.join('tmp')
@gem = Pathname(__dir__).join('..', '..').realpath
@current = ENV['RODBOT_ENV']
@current = ENV['RODBOT_ENV'] || ENV['APP_ENV']
@current = 'development' unless ENVS.include? @current
end

Expand Down
16 changes: 16 additions & 0 deletions spec/lib/rodbot/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,20 @@
end
end
end

describe 'APP_ENV environment variable' do
it "sets the environment" do
with "ENV['APP_ENV']", 'production' do
with "ENV['RODBOT_ENV']", nil do
_(subject).must_be :production?
end
end
end

it "RODBOT_ENV takes precedence" do
with "ENV['APP_ENV']", 'production' do
_(subject).must_be :test?
end
end
end
end

0 comments on commit 4f48037

Please sign in to comment.