Skip to content

Commit 428c50b

Browse files
authored
Add documentation (#10)
1 parent 866f979 commit 428c50b

File tree

3 files changed

+114
-17
lines changed

3 files changed

+114
-17
lines changed

README.md

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,125 @@
1-
# Rails::AppEnv
2-
Short description and motivation.
1+
<div align="center">
32

4-
## Usage
5-
How to use my plugin.
3+
# Rails APP_ENV
64

7-
## Installation
8-
Add this line to your application's Gemfile:
5+
[![Gem Version](https://img.shields.io/gem/v/rails-app_env)](https://badge.fury.io/rb/rails-app_env)
6+
[![CI](https://github.com/typisttech/rails-app_env/actions/workflows/ci.yml/badge.svg)](https://github.com/typisttech/rails-app_env/actions/workflows/ci.yml)
7+
[![License](https://img.shields.io/github/license/typisttech/rails-app_env.svg)](https://github.com/typisttech/rails-app_env/blob/master/LICENSE.txt)
8+
[![Follow @TangRufus on X](https://img.shields.io/badge/Follow-TangRufus-15202B?logo=x&logoColor=white)](https://x.com/tangrufus)
9+
[![Follow @TangRufus.com on Bluesky](https://img.shields.io/badge/Bluesky-TangRufus.com-blue?logo=bluesky)](https://bsky.app/profile/tangrufus.com)
10+
[![Sponsor @TangRufus via GitHub](https://img.shields.io/badge/Sponsor-TangRufus-EA4AAA?logo=githubsponsors)](https://github.com/sponsors/tangrufus)
11+
[![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-778899)](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.
947

1048
```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
1258
```
1359

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
1776
```
1877

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+
![rails console](docs/screenshot-rails-console.jpg)
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+
20103
```bash
21-
$ gem install rails-app_env
104+
bundle add rails-app_env
22105
```
23106

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
26124

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.

docs/screenshot-rails-console.jpg

72.7 KB
Loading

rails-app_env.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
66
spec.authors = ["Typist Tech Limited", "Tang Rufus"]
77
spec.email = ["opensource+swagger_ui_standalone@typist.tech", "tangrufus@gmail.com"]
88

9-
spec.summary = "Summary of Rails::AppEnv."
9+
spec.summary = "Rails APP_ENV is like RAILS_ENV but for configurations only."
1010
spec.homepage = "https://github.com/typisttech/rails-app_env"
1111
spec.license = "MIT"
1212
spec.required_ruby_version = ">= 3.2.0"

0 commit comments

Comments
 (0)