|
1 | | -# Rails::AppEnv |
2 | | -Short description and motivation. |
| 1 | +<div align="center"> |
3 | 2 |
|
4 | | -## Usage |
5 | | -How to use my plugin. |
| 3 | +# Rails APP_ENV |
6 | 4 |
|
7 | | -## Installation |
8 | | -Add this line to your application's Gemfile: |
| 5 | +[](https://badge.fury.io/rb/rails-app_env) |
| 6 | +[](https://github.com/typisttech/rails-app_env/actions/workflows/ci.yml) |
| 7 | +[](https://github.com/typisttech/rails-app_env/blob/master/LICENSE.txt) |
| 8 | +[](https://x.com/tangrufus) |
| 9 | +[](https://bsky.app/profile/tangrufus.com) |
| 10 | +[](https://github.com/sponsors/tangrufus) |
| 11 | +[](https://typist.tech/contact/) |
| 12 | + |
| 13 | +<p> |
| 14 | + <strong> |
| 15 | + <code>Rails APP_ENV</code> is like <code>RAILS_ENV</code> but for configurations only. |
| 16 | + </strong> |
| 17 | + <br> |
| 18 | + <br> |
| 19 | + Built with ♥ by <a href="https://typist.tech/">Typist Tech</a> |
| 20 | +</p> |
| 21 | + |
| 22 | +</div> |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Quick Start |
| 27 | + |
| 28 | +TODO. |
| 29 | + |
| 30 | +## Why |
| 31 | + |
| 32 | +TODO. |
| 33 | + |
| 34 | +## `RAILS_ENV` vs `APP_ENV` |
| 35 | + |
| 36 | +TODO. |
| 37 | + |
| 38 | +## Features |
| 39 | + |
| 40 | +### `Rails.app_env` |
| 41 | + |
| 42 | +`Rails.app_env` is like `Rails.env` but it is set by the `APP_ENV` environment variable (`ENV["APP_ENV"]`). |
| 43 | + |
| 44 | +It is optimization for `staging` and `review` ([the two extra Heroku pipeline stages](https://devcenter.heroku.com/articles/pipelines)), |
| 45 | +so it doesn't need to rely on the slower delegation through `method_missing` that `ActiveSupport::EnvironmentInquirer` |
| 46 | +would normally entail. |
9 | 47 |
|
10 | 48 | ```ruby |
11 | | -gem "rails-app_env" |
| 49 | +## Assume we booted Rails with `APP_ENV=staging RAILS_ENV=production` |
| 50 | +Rails.app_env # => "staging" |
| 51 | +Rails.app_env.staging? # => true |
| 52 | +Rails.app_env.production? # => false |
| 53 | +Rails.app_env.any_other_predicate? # => false |
| 54 | + |
| 55 | +Rails.env # => "production" |
| 56 | +Rails.env.staging? # => false |
| 57 | +Rails.env.production? # => true |
12 | 58 | ``` |
13 | 59 |
|
14 | | -And then execute: |
15 | | -```bash |
16 | | -$ bundle |
| 60 | +In case `ENV["APP_ENV"]` is blank, `Rails.app_env` falls back to `Rails.env`. |
| 61 | + |
| 62 | +### Credentials |
| 63 | + |
| 64 | +`Rails APP_ENV` overrides the default Rails credentials `content_path` and `key_path` according to `Rails.app_env`. |
| 65 | + |
| 66 | +Given the following `*.yml.enc` and `*.key` files under `config/credentials/`, `APP_ENV=staging RAILS_ENV=production` |
| 67 | +would load the credentials from `config/credentials/staging.yml.enc` and `config/credentials/staging.key`. |
| 68 | + |
| 69 | +```console |
| 70 | +$ tree config/credentials |
| 71 | +config/credentials |
| 72 | +├── production.key |
| 73 | +├── production.yml.enc |
| 74 | +├── staging.key |
| 75 | +└── staging.yml.enc |
17 | 76 | ``` |
18 | 77 |
|
19 | | -Or install it yourself as: |
| 78 | +In case `config/credentials/#{Rails.app_env}.yml.enc` does not exist, it falls back to `config/credentials.yml.enc`. |
| 79 | + |
| 80 | +In case `config/credentials/#{Rails.app_env}.key` does not exist, it falls back to `config/master.key`. |
| 81 | + |
| 82 | +As with default Rails behaviours, if `ENV["RAILS_MASTER_KEY"]` is present, it takes precedence over |
| 83 | +`config/credentials/#{Rails.app_env}.key` and `config/master.key`. |
| 84 | + |
| 85 | +Learn more in the [Heroku](#heroku) section below. |
| 86 | + |
| 87 | +### Console |
| 88 | + |
| 89 | +Whenever Rails console is started, `Rails APP_ENV` prints the current `Rails.app_env` and gem version to the console. |
| 90 | + |
| 91 | +If the `Rails.app_env` differs from `Rials.env`, `Rails APP_ENV` appends `Rails.app_env` to the console prompt. |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +## Heroku |
| 96 | + |
| 97 | +TODO. |
| 98 | + |
| 99 | +## Installation |
| 100 | + |
| 101 | +Install the gem and add to the application's `Gemfile` or `gems.rb` by executing: |
| 102 | + |
20 | 103 | ```bash |
21 | | -$ gem install rails-app_env |
| 104 | +bundle add rails-app_env |
22 | 105 | ``` |
23 | 106 |
|
24 | | -## Contributing |
25 | | -Contribution directions go here. |
| 107 | +## Prior Art |
| 108 | + |
| 109 | +- [anyway_config](https://github.com/palkan/anyway_config) |
| 110 | + |
| 111 | +## Credits |
| 112 | + |
| 113 | +[`Rails APP_ENV`](https://github.com/typisttech/rails-app_env) is a [Typist Tech](https://typist.tech) project and |
| 114 | +maintained by [Tang Rufus](https://x.com/TangRufus), freelance developer [for hire](https://typist.tech/contact/). |
| 115 | + |
| 116 | +Full list of contributors can be found [on GitHub](https://github.com/typisttech/rails-app_env/graphs/contributors). |
| 117 | + |
| 118 | +## Copyright and License |
| 119 | + |
| 120 | +This project is a [free software](https://www.gnu.org/philosophy/free-sw.en.html) distributed under the terms of |
| 121 | +the MIT license. For the full license, see [LICENSE](LICENSE). |
| 122 | + |
| 123 | +## Contribute |
26 | 124 |
|
27 | | -## License |
28 | | -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
| 125 | +Feedbacks / bug reports / pull requests are welcome. |
0 commit comments