daqing_figaro 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +123 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +345 -0
- data/Rakefile +6 -0
- data/bin/figaro +5 -0
- data/figaro.gemspec +23 -0
- data/gemfiles/rails52.gemfile +11 -0
- data/gemfiles/rails6.gemfile +11 -0
- data/gemfiles/rails60.gemfile +11 -0
- data/lib/figaro/application.rb +91 -0
- data/lib/figaro/cli/heroku_set.rb +33 -0
- data/lib/figaro/cli/install/application.yml +11 -0
- data/lib/figaro/cli/install.rb +32 -0
- data/lib/figaro/cli/task.rb +37 -0
- data/lib/figaro/cli.rb +42 -0
- data/lib/figaro/env.rb +45 -0
- data/lib/figaro/error.rb +17 -0
- data/lib/figaro/rails/application.rb +21 -0
- data/lib/figaro/rails/railtie.rb +9 -0
- data/lib/figaro/rails/tasks.rake +6 -0
- data/lib/figaro/rails.rb +9 -0
- data/lib/figaro.rb +32 -0
- data/spec/figaro/application_spec.rb +262 -0
- data/spec/figaro/cli/heroku_set_spec.rb +67 -0
- data/spec/figaro/cli/install_spec.rb +49 -0
- data/spec/figaro/env_spec.rb +195 -0
- data/spec/figaro/rails/application_spec.rb +41 -0
- data/spec/figaro_spec.rb +99 -0
- data/spec/rails_spec.rb +55 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/aruba.rb +18 -0
- data/spec/support/bin/heroku +5 -0
- data/spec/support/command_helpers.rb +17 -0
- data/spec/support/command_interceptor.rb +33 -0
- data/spec/support/reset.rb +13 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d69e1bf960d7a400403d626f42294c8d79c6b56f4e7afe7dda22bb1afe1a899f
|
4
|
+
data.tar.gz: 798f147ca7a1d8531938bf8f76848a3a72351e78c6685b0240a74d3dad58cc40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e08ed4408d112be11ce18f3fcc48d1c4227d7ddcbea881f70d14446cd2b0dc284e6ce7cb62d70f6e3026943c8f9e08667f6c138a75f37f03d00103cf39fd8e7
|
7
|
+
data.tar.gz: 1409a5b13fc45b7eda49de6f697d6b6d2cb85637a9f1e630b12004b974c4d468767eff1430619d756dc01ff1c32eed9f20552ceb52775e057399e6f4f35ddb39
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: [laserlemon]
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem update bundler rake
|
3
|
+
before_script:
|
4
|
+
- unset RAILS_ENV
|
5
|
+
- unset RACK_ENV
|
6
|
+
branches:
|
7
|
+
only:
|
8
|
+
- master
|
9
|
+
gemfile:
|
10
|
+
- gemfiles/rails52.gemfile
|
11
|
+
- gemfiles/rails60.gemfile
|
12
|
+
- gemfiles/rails6.gemfile
|
13
|
+
jobs:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
- gemfile: gemfiles/rails6.gemfile
|
17
|
+
language: ruby
|
18
|
+
rvm:
|
19
|
+
- "2.5"
|
20
|
+
- "2.6"
|
21
|
+
- "2.7"
|
22
|
+
- ruby-head
|
23
|
+
script: bundle exec rspec
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
## 1.2.0 / 2020-05-10
|
2
|
+
|
3
|
+
* [ENHANCEMENT] Drop support for Rubies 1.9.3, 2.0, 2.1, and 2.2
|
4
|
+
* [ENHANCEMENT] Add support for Rubies 2.5, 2.6, and 2.7
|
5
|
+
* [ENHANCEMENT] Drop support for Rails 3 and 4
|
6
|
+
* [ENHANCEMENT] Add support for Rails 5.2 and 6.0
|
7
|
+
* [ENHANCEMENT] Proxy all ENV values via CLI to the "heroku" command
|
8
|
+
|
9
|
+
## 1.1.1 / 2015-04-30
|
10
|
+
|
11
|
+
* [BUGFIX] Fix crash when environment-specific configuration is `nil`
|
12
|
+
|
13
|
+
## 1.1.0 / 2015-01-27
|
14
|
+
|
15
|
+
* [FEATURE] Support --remote when setting Heroku configuration
|
16
|
+
* [ENHANCEMENT] Test against Rails 4.2 (stable)
|
17
|
+
|
18
|
+
## 1.0.0 / 2014-09-17
|
19
|
+
|
20
|
+
* [BUGFIX] Make calls to Heroku with a clean Bundler environment
|
21
|
+
* [ENHANCEMENT] Remove Rails as a runtime dependency
|
22
|
+
* [FEATURE] Replace the Rails generator with the `figaro install` task
|
23
|
+
* [ENHANCEMENT] Rename the `Figaro.require` method to `Figaro.require_keys`
|
24
|
+
* [ENHANCEMENT] Begin to test against Rails 4.2 (beta)
|
25
|
+
|
26
|
+
## 1.0.0.rc1 / 2014-04-17
|
27
|
+
|
28
|
+
* [FEATURE] Add bang and boolean methods to `Figaro.env`
|
29
|
+
* [ENHANCEMENT] Detach `Figaro.env` from the configuration file hash
|
30
|
+
* [FEATURE] Add the ability to swap Figaro's application adapter
|
31
|
+
* [FEATURE] Warn when configuration keys or values are not strings
|
32
|
+
* [FEATURE] Enable Figaro to load multiple times, overwriting previous values
|
33
|
+
* [FEATURE] Load Figaro configuration prior to database configuration
|
34
|
+
* [ENHANCEMENT] Test against Ruby 2.1
|
35
|
+
* [ENHANCEMENT] Test against Rails 4.1
|
36
|
+
* [FEATURE] Replace Rake task with `figaro` executable
|
37
|
+
* [BUGFIX] Fix character escaping for `figaro heroku:set` on Windows
|
38
|
+
* [FEATURE] Warn when a preexisting configuration key is skipped during load
|
39
|
+
* [FEATURE] Add the ability to fail fast in the absence of required keys
|
40
|
+
* [FEATURE] Tie into Rails' earliest possible `before_configuration` hook
|
41
|
+
|
42
|
+
## 0.7.0 / 2013-06-27
|
43
|
+
|
44
|
+
* [FEATURE] Allow configuration values to be overridden on the system level
|
45
|
+
* [FEATURE] Enable ERB evaluation of the configuration file
|
46
|
+
|
47
|
+
## 0.6.4 / 2013-05-01
|
48
|
+
|
49
|
+
* [BUGFIX] Make the configuration file path platform-independent
|
50
|
+
* [FEATURE] Make `Figaro.env` proxy method calls case-insensitive
|
51
|
+
|
52
|
+
## 0.6.3 / 2013-03-10
|
53
|
+
|
54
|
+
* [BUGFIX] Run Heroku commands with a clean Bundler environment
|
55
|
+
|
56
|
+
## 0.6.2 / 2013-03-07
|
57
|
+
|
58
|
+
* [ENHANCEMENT] Refactor `figaro:heroku` task into a unit-tested class
|
59
|
+
* [ENHANCEMENT] Relax development gem dependency version requirements
|
60
|
+
* [ENHANCEMENT] Track test coverage
|
61
|
+
|
62
|
+
## 0.6.1 / 2013-02-27
|
63
|
+
|
64
|
+
* [ENHANCEMENT] Declare development gem dependencies in gemfiles
|
65
|
+
* [BUGFIX] Cast boolean configuration values to strings
|
66
|
+
* [ENHANCEMENT] Use RSpec `expect` syntax
|
67
|
+
|
68
|
+
## 0.6.0 / 2013-02-26
|
69
|
+
|
70
|
+
* [ENHANCEMENT] Test against Ruby 2.0.0
|
71
|
+
* [ENHANCEMENT] Test against Rails 4.0
|
72
|
+
|
73
|
+
## 0.5.4 / 2013-02-22
|
74
|
+
|
75
|
+
* [ENHANCEMENT] GitHub Ruby Styleguide conventions
|
76
|
+
* [ENHANCEMENT] Remove unnecessary development dependencies
|
77
|
+
* [FEATURE] Allow `nil` values in `Figaro.env`
|
78
|
+
|
79
|
+
## 0.5.3 / 2013-01-12
|
80
|
+
|
81
|
+
* [BUGFIX] Fix `figaro:heroku` to properly capture standard output... again
|
82
|
+
|
83
|
+
## 0.5.2 / 2013-01-07
|
84
|
+
|
85
|
+
* [BUGFIX] Escape special characters in the `figaro:heroku` task
|
86
|
+
|
87
|
+
## 0.5.1 / 2013-01-07
|
88
|
+
|
89
|
+
* [BUGFIX] Fix `figaro:heroku` to properly capture standard output
|
90
|
+
|
91
|
+
## 0.5.0 / 2012-10-28
|
92
|
+
|
93
|
+
* [BUGFIX] Automatically cast configuration keys and values to strings
|
94
|
+
* [FEATURE] Allow the `figaro:heroku` task to respect remote Rails environment
|
95
|
+
* [FEATURE] Enable `Figaro.env` to act as a proxy to `ENV`
|
96
|
+
|
97
|
+
## 0.4.1 / 2012-04-25
|
98
|
+
|
99
|
+
* [BUGFIX] Fix `figaro:heroku` Rake task failures
|
100
|
+
|
101
|
+
## 0.4.0 / 2012-04-20
|
102
|
+
|
103
|
+
* [FEATURE] Allow environment-specific configuration
|
104
|
+
|
105
|
+
## 0.3.0 / 2012-04-20
|
106
|
+
|
107
|
+
* [ENHANCEMENT] Refactor the loading configuration into `ENV`
|
108
|
+
* [FEATURE] Add `figaro:heroku` Rake task
|
109
|
+
|
110
|
+
## 0.2.0 / 2012-04-03
|
111
|
+
|
112
|
+
* [ENHANCEMENT] Test against multiple Rails versions (3.0, 3.1, 3.2)
|
113
|
+
* [FEATURE] Add `figaro:install` Rails generator
|
114
|
+
* [BUGFIX] Gracefully parse YAML files containing only comments
|
115
|
+
|
116
|
+
## 0.1.1 / 2012-04-02
|
117
|
+
|
118
|
+
* [ENHANCEMENT] Remove RSpec development gem dependency
|
119
|
+
* [ENHANCEMENT] Introduce Figaro, the mascot
|
120
|
+
|
121
|
+
## 0.1.0 / 2012-04-02
|
122
|
+
|
123
|
+
* Initial release!
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Contributing to Figaro
|
2
|
+
|
3
|
+
Figaro is open source and contributions from the community are encouraged! No
|
4
|
+
contribution is too small.
|
5
|
+
|
6
|
+
Please consider:
|
7
|
+
|
8
|
+
* Adding a feature
|
9
|
+
* Squashing a bug
|
10
|
+
* Writing documentation
|
11
|
+
* Fixing a typo
|
12
|
+
* Correcting [style](https://github.com/styleguide/ruby)
|
13
|
+
|
14
|
+
## How do I contribute?
|
15
|
+
|
16
|
+
For the best chance of having your changes merged, please:
|
17
|
+
|
18
|
+
1. [Fork](https://github.com/laserlemon/figaro/fork) the project.
|
19
|
+
2. [Write](http://en.wikipedia.org/wiki/Test-driven_development) a failing test.
|
20
|
+
3. [Commit](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) changes that fix the tests.
|
21
|
+
4. [Submit](https://github.com/laserlemon/figaro/pulls) a pull request with *at least* one animated GIF.
|
22
|
+
5. Be patient.
|
23
|
+
|
24
|
+
If your proposed changes only affect documentation, include the following on a
|
25
|
+
new line in each of your commit messages:
|
26
|
+
|
27
|
+
```
|
28
|
+
[ci skip]
|
29
|
+
```
|
30
|
+
|
31
|
+
This will signal [Travis](https://travis-ci.org) that running the test suite is
|
32
|
+
not necessary for these changes.
|
33
|
+
|
34
|
+
## Bug Reports
|
35
|
+
|
36
|
+
If you are experiencing unexpected behavior and, after having read Figaro's
|
37
|
+
documentation, are convinced this behavior is a bug, please:
|
38
|
+
|
39
|
+
1. [Search](https://github.com/laserlemon/figaro/issues) existing issues.
|
40
|
+
2. Collect enough information to reproduce the issue:
|
41
|
+
* Figaro version
|
42
|
+
* Ruby version
|
43
|
+
* Rails version
|
44
|
+
* Specific setup conditions
|
45
|
+
* Description of expected behavior
|
46
|
+
* Description of actual behavior
|
47
|
+
3. [Submit](https://github.com/laserlemon/figaro/issues/new) an issue.
|
48
|
+
4. Be patient.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Steve Richert
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,345 @@
|
|
1
|
+
## 📢 UPDATE
|
2
|
+
|
3
|
+
Figaro [v2](https://github.com/laserlemon/figaro/tree/v2) development is underway but _stalled_. I need your help! Please consider [sponsoring Figaro's development](https://github.com/sponsors/laserlemon).
|
4
|
+
|
5
|
+
With the constraints of a family and a full-time job, even the _emotional_ support that sponsorship provides is extremely valuable in re-energizing Figaro development. Thank you! 💛
|
6
|
+
|
7
|
+
# 
|
8
|
+
|
9
|
+
Simple, Heroku-friendly Rails app configuration using `ENV` and a single YAML file
|
10
|
+
|
11
|
+
[](http://badge.fury.io/rb/figaro)
|
12
|
+
[](https://travis-ci.org/laserlemon/figaro)
|
13
|
+
|
14
|
+
**NOTE:** If you're using Figaro 0.7 or prior, please refer to the
|
15
|
+
[appropriate documentation](https://github.com/laserlemon/figaro/tree/0-stable#readme)
|
16
|
+
or [upgrade](#how-do-i-upgrade-to-figaro-10) to Figaro 1.0.
|
17
|
+
|
18
|
+
## Why does Figaro exist?
|
19
|
+
|
20
|
+
Figaro was written to make it easy to securely configure Rails applications.
|
21
|
+
|
22
|
+
Configuration values often include sensitive information. Figaro strives to be
|
23
|
+
secure by default by encouraging a convention that keeps configuration out of
|
24
|
+
Git.
|
25
|
+
|
26
|
+
## How does Figaro work?
|
27
|
+
|
28
|
+
Figaro is inspired by the [Twelve-Factor App](http://12factor.net) methodology,
|
29
|
+
which states:
|
30
|
+
|
31
|
+
> The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.
|
32
|
+
|
33
|
+
This is straightforward in production environments but local development
|
34
|
+
environments are often shared between multiple applications, requiring multiple
|
35
|
+
configurations.
|
36
|
+
|
37
|
+
Figaro parses a Git-ignored YAML file in your application and loads its values
|
38
|
+
into `ENV`.
|
39
|
+
|
40
|
+
### Getting Started
|
41
|
+
|
42
|
+
Add Figaro to your Gemfile and `bundle install`:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem "figaro"
|
46
|
+
```
|
47
|
+
|
48
|
+
Figaro installation is easy:
|
49
|
+
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ bundle exec figaro install
|
53
|
+
```
|
54
|
+
|
55
|
+
This creates a commented `config/application.yml` file and adds it to your
|
56
|
+
`.gitignore`. Add your own configuration to this file and you're done!
|
57
|
+
|
58
|
+
### Example
|
59
|
+
|
60
|
+
Given the following configuration file:
|
61
|
+
|
62
|
+
```yaml
|
63
|
+
# config/application.yml
|
64
|
+
|
65
|
+
pusher_app_id: "2954"
|
66
|
+
pusher_key: "7381a978f7dd7f9a1117"
|
67
|
+
pusher_secret: "abdc3b896a0ffb85d373"
|
68
|
+
```
|
69
|
+
|
70
|
+
You can configure [Pusher](http://pusher.com) in an initializer:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# config/initializers/pusher.rb
|
74
|
+
|
75
|
+
Pusher.app_id = ENV["pusher_app_id"]
|
76
|
+
Pusher.key = ENV["pusher_key"]
|
77
|
+
Pusher.secret = ENV["pusher_secret"]
|
78
|
+
```
|
79
|
+
|
80
|
+
**Please note:** `ENV` is a simple key/value store. All values will be converted
|
81
|
+
to strings. Deeply nested configuration structures are not possible.
|
82
|
+
|
83
|
+
### Environment-Specific Configuration
|
84
|
+
|
85
|
+
Oftentimes, local configuration values change depending on Rails environment. In
|
86
|
+
such cases, you can add environment-specific values to your configuration file:
|
87
|
+
|
88
|
+
```yaml
|
89
|
+
# config/application.yml
|
90
|
+
|
91
|
+
pusher_app_id: "2954"
|
92
|
+
pusher_key: "7381a978f7dd7f9a1117"
|
93
|
+
pusher_secret: "abdc3b896a0ffb85d373"
|
94
|
+
|
95
|
+
test:
|
96
|
+
pusher_app_id: "5112"
|
97
|
+
pusher_key: "ad69caf9a44dcac1fb28"
|
98
|
+
pusher_secret: "83ca7aa160fedaf3b350"
|
99
|
+
```
|
100
|
+
|
101
|
+
You can also nullify configuration values for a specific environment:
|
102
|
+
|
103
|
+
```yaml
|
104
|
+
# config/application.yml
|
105
|
+
|
106
|
+
google_analytics_key: "UA-35722661-5"
|
107
|
+
|
108
|
+
test:
|
109
|
+
google_analytics_key: ~
|
110
|
+
```
|
111
|
+
|
112
|
+
### Using `Figaro.env`
|
113
|
+
|
114
|
+
`Figaro.env` is a convenience that acts as a proxy to `ENV`.
|
115
|
+
|
116
|
+
In testing, it is sometimes more convenient to stub and unstub `Figaro.env` than
|
117
|
+
to set and reset `ENV`. Whether your application uses `ENV` or `Figaro.env` is
|
118
|
+
entirely a matter of personal preference.
|
119
|
+
|
120
|
+
```yaml
|
121
|
+
# config/application.yml
|
122
|
+
|
123
|
+
stripe_api_key: "sk_live_dSqzdUq80sw9GWmuoI0qJ9rL"
|
124
|
+
```
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
ENV["stripe_api_key"] # => "sk_live_dSqzdUq80sw9GWmuoI0qJ9rL"
|
128
|
+
ENV.key?("stripe_api_key") # => true
|
129
|
+
ENV["google_analytics_key"] # => nil
|
130
|
+
ENV.key?("google_analytics_key") # => false
|
131
|
+
|
132
|
+
Figaro.env.stripe_api_key # => "sk_live_dSqzdUq80sw9GWmuoI0qJ9rL"
|
133
|
+
Figaro.env.stripe_api_key? # => true
|
134
|
+
Figaro.env.google_analytics_key # => nil
|
135
|
+
Figaro.env.google_analytics_key? # => false
|
136
|
+
```
|
137
|
+
|
138
|
+
### Required Keys
|
139
|
+
|
140
|
+
If a particular configuration value is required but not set, it's appropriate to
|
141
|
+
raise an error. With Figaro, you can either raise these errors proactively or
|
142
|
+
lazily.
|
143
|
+
|
144
|
+
To proactively require configuration keys:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
# config/initializers/figaro.rb
|
148
|
+
|
149
|
+
Figaro.require_keys("pusher_app_id", "pusher_key", "pusher_secret")
|
150
|
+
```
|
151
|
+
|
152
|
+
If any of the configuration keys above are not set, your application will raise
|
153
|
+
an error during initialization. This method is preferred because it prevents
|
154
|
+
runtime errors in a production application due to improper configuration.
|
155
|
+
|
156
|
+
To require configuration keys lazily, reference the variables via "bang" methods
|
157
|
+
on `Figaro.env`:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
# config/initializers/pusher.rb
|
161
|
+
|
162
|
+
Pusher.app_id = Figaro.env.pusher_app_id!
|
163
|
+
Pusher.key = Figaro.env.pusher_key!
|
164
|
+
Pusher.secret = Figaro.env.pusher_secret!
|
165
|
+
```
|
166
|
+
|
167
|
+
### Deployment
|
168
|
+
|
169
|
+
Figaro is written with deployment in mind. In fact, [Heroku](https://www.heroku.com)'s
|
170
|
+
use of `ENV` for application configuration was the original inspiration for
|
171
|
+
Figaro.
|
172
|
+
|
173
|
+
#### Heroku
|
174
|
+
|
175
|
+
Heroku already makes setting application configuration easy:
|
176
|
+
|
177
|
+
```bash
|
178
|
+
$ heroku config:set google_analytics_key=UA-35722661-5
|
179
|
+
```
|
180
|
+
|
181
|
+
Using the `figaro` command, you can set values from your configuration file all
|
182
|
+
at once:
|
183
|
+
|
184
|
+
```bash
|
185
|
+
$ figaro heroku:set -e production
|
186
|
+
```
|
187
|
+
|
188
|
+
For more information:
|
189
|
+
|
190
|
+
```bash
|
191
|
+
$ figaro help heroku:set
|
192
|
+
```
|
193
|
+
|
194
|
+
#### Other Hosts
|
195
|
+
|
196
|
+
If you're not deploying to Heroku, you have two options:
|
197
|
+
|
198
|
+
* Generate a remote configuration file
|
199
|
+
* Set `ENV` variables directly
|
200
|
+
|
201
|
+
Generating a remote configuration file is preferred because of:
|
202
|
+
|
203
|
+
* familiarity – Management of `config/application.yml` is like that of `config/database.yml`.
|
204
|
+
* isolation – Multiple applications on the same server will not produce configuration key collisions.
|
205
|
+
|
206
|
+
## Is Figaro like [dotenv](https://github.com/bkeepers/dotenv)?
|
207
|
+
|
208
|
+
Yes. Kind of.
|
209
|
+
|
210
|
+
Figaro and dotenv were written around the same time to solve similar problems.
|
211
|
+
|
212
|
+
### Similarities
|
213
|
+
|
214
|
+
* Both libraries are useful for Ruby application configuration.
|
215
|
+
* Both are popular and well maintained.
|
216
|
+
* Both are inspired by Twelve-Factor App's concept of proper [configuration](http://12factor.net/config).
|
217
|
+
* Both store configuration values in `ENV`.
|
218
|
+
|
219
|
+
### Differences
|
220
|
+
|
221
|
+
* Configuration File
|
222
|
+
* Figaro expects a single file.
|
223
|
+
* Dotenv supports separate files for each environment.
|
224
|
+
* Configuration File Format
|
225
|
+
* Figaro expects YAML containing key/value pairs.
|
226
|
+
* Dotenv convention is a collection of `KEY=VALUE` pairs.
|
227
|
+
* Security vs. Convenience
|
228
|
+
* Figaro convention is to never commit configuration files.
|
229
|
+
* Dotenv encourages committing configuration files containing development values.
|
230
|
+
* Framework Focus
|
231
|
+
* Figaro was written with a focus on Rails development and conventions.
|
232
|
+
* Dotenv was written to accommodate any type of Ruby application.
|
233
|
+
|
234
|
+
Either library may suit your configuration needs. It often boils down to
|
235
|
+
personal preference.
|
236
|
+
|
237
|
+
## Is application.yml like [secrets.yml](https://github.com/rails/rails/blob/v4.1.0/railties/lib/rails/generators/rails/app/templates/config/secrets.yml)?
|
238
|
+
|
239
|
+
Yes. Kind of.
|
240
|
+
|
241
|
+
Rails 4.1 introduced the `secrets.yml` convention for Rails application
|
242
|
+
configuration. Figaro predated the Rails 4.1 release by two years.
|
243
|
+
|
244
|
+
### Similarities
|
245
|
+
|
246
|
+
* Both are useful for Rails application configuration.
|
247
|
+
* Both are popular and well maintained.
|
248
|
+
* Both expect a single YAML file.
|
249
|
+
|
250
|
+
### Differences
|
251
|
+
|
252
|
+
* Configuration Access
|
253
|
+
* Figaro stores configuration values in `ENV`.
|
254
|
+
* Rails stores configuration values in `Rails.application.secrets`.
|
255
|
+
* Configuration File Structure
|
256
|
+
* Figaro expects YAML containing key/value string pairs.
|
257
|
+
* Secrets may contain nested structures with rich objects.
|
258
|
+
* Security vs. Convenience
|
259
|
+
* Figaro convention is to never commit configuration files.
|
260
|
+
* Secrets are committed by default.
|
261
|
+
* Consistency
|
262
|
+
* Figaro uses `ENV` for configuration in every environment.
|
263
|
+
* Secrets encourage using `ENV` for production only.
|
264
|
+
* Approach
|
265
|
+
* Figaro is inspired by Twelve-Factor App's concept of proper [configuration](http://12factor.net/config).
|
266
|
+
* Secrets are… not.
|
267
|
+
|
268
|
+
The emergence of a configuration convention for Rails is an important step, but
|
269
|
+
as long as the last three differences above exist, Figaro will continue to be
|
270
|
+
developed as a more secure, more consistent, and more standards-compliant
|
271
|
+
alternative to `secrets.yml`.
|
272
|
+
|
273
|
+
For more information, read the original [The Marriage of Figaro… and Rails](http://www.collectiveidea.com/blog/archives/2013/12/18/the-marriage-of-figaro-and-rails/) blog post.
|
274
|
+
|
275
|
+
## How do I upgrade to Figaro 1.0?
|
276
|
+
|
277
|
+
In most cases, upgrading from Figaro 0.7 to 1.0 is painless. The format
|
278
|
+
expectations for `application.yml` are the same in 1.0 and values from
|
279
|
+
`application.yml` are loaded into `ENV` as they were in 0.7.
|
280
|
+
|
281
|
+
However, there are breaking changes:
|
282
|
+
|
283
|
+
### `Figaro.env`
|
284
|
+
|
285
|
+
In Figaro 0.7, calling a method on the `Figaro.env` proxy would raise an error
|
286
|
+
if a corresponding key were not set in `ENV`.
|
287
|
+
|
288
|
+
In Figaro 1.0, calling a method on `Figaro.env` corresponding to an unset key
|
289
|
+
will return `nil`. To emulate the behavior of Figaro 0.7, use "bang" methods as
|
290
|
+
described in the [Required Keys](#required-keys) section.
|
291
|
+
|
292
|
+
**NOTE:** In Figaro 0.7, `Figaro.env` inherited from `Hash` but in Figaro 1.0,
|
293
|
+
hash access has been removed.
|
294
|
+
|
295
|
+
### Heroku Configuration
|
296
|
+
|
297
|
+
In Figaro 0.7, a Rake task existed to set remote Heroku configuration according
|
298
|
+
to values in `application.yml`.
|
299
|
+
|
300
|
+
In Figaro 1.0, the Rake task was replaced by a command for the `figaro`
|
301
|
+
executable:
|
302
|
+
|
303
|
+
```bash
|
304
|
+
$ figaro heroku:set -e production
|
305
|
+
```
|
306
|
+
|
307
|
+
For more information:
|
308
|
+
|
309
|
+
```bash
|
310
|
+
$ figaro help heroku:set
|
311
|
+
```
|
312
|
+
|
313
|
+
**NOTE:** The environment option is required for the `heroku:set` command. The
|
314
|
+
Rake task in Figaro 0.7 used the default of "development" if unspecified.
|
315
|
+
|
316
|
+
### Spring Configuration
|
317
|
+
|
318
|
+
If you're using Spring, either [stop](http://collectiveidea.com/blog/archives/2015/02/04/spring-is-dead-to-me)
|
319
|
+
or add `config/application.yml` to the watch list:
|
320
|
+
|
321
|
+
```rb
|
322
|
+
# config/spring.rb
|
323
|
+
|
324
|
+
%w(
|
325
|
+
...
|
326
|
+
config/application.yml
|
327
|
+
).each { |path| Spring.watch(path) }
|
328
|
+
```
|
329
|
+
|
330
|
+
## Who wrote Figaro?
|
331
|
+
|
332
|
+
My name is Steve Richert and I wrote Figaro in March, 2012 with overwhelming
|
333
|
+
encouragement from my employer, [Collective Idea](http://www.collectiveidea.com).
|
334
|
+
Figaro has improved very much since then, thanks entirely to [inspiration](https://github.com/laserlemon/figaro/issues)
|
335
|
+
and [contribution](https://github.com/laserlemon/figaro/graphs/contributors)
|
336
|
+
from developers everywhere.
|
337
|
+
|
338
|
+
**Thank you!**
|
339
|
+
|
340
|
+
## How can I help?
|
341
|
+
|
342
|
+
Figaro is open source and contributions from the community are encouraged! No
|
343
|
+
contribution is too small.
|
344
|
+
|
345
|
+
See Figaro's [contribution guidelines](CONTRIBUTING.md) for more information.
|
data/Rakefile
ADDED
data/bin/figaro
ADDED
data/figaro.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "daqing_figaro"
|
5
|
+
gem.version = "1.2.1"
|
6
|
+
|
7
|
+
gem.author = "David Zhang"
|
8
|
+
gem.email = "daqing@icloud.com"
|
9
|
+
gem.summary = "Simple Rails app configuration"
|
10
|
+
gem.description = "Simple, Heroku-friendly Rails app configuration using ENV and a single YAML file"
|
11
|
+
gem.homepage = "https://github.com/daqing/figaro"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.add_dependency "thor", ">= 0.14.0", "< 2"
|
15
|
+
|
16
|
+
gem.add_development_dependency "bundler", ">= 1.7.0", "< 3"
|
17
|
+
gem.add_development_dependency "rake", ">= 10.4.0", "< 14"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($\)
|
20
|
+
gem.test_files = gem.files.grep(/^spec/)
|
21
|
+
|
22
|
+
gem.executables << "figaro"
|
23
|
+
end
|