drtom_rails_config 0.5.0.beta1
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/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +24 -0
- data/Gemfile +6 -0
- data/LICENSE.md +27 -0
- data/README.md +317 -0
- data/Rakefile +53 -0
- data/gemfiles/rails_3.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/lib/generators/rails_config/install_generator.rb +32 -0
- data/lib/generators/rails_config/templates/rails_config.rb +3 -0
- data/lib/generators/rails_config/templates/settings.local.yml +0 -0
- data/lib/generators/rails_config/templates/settings.yml +0 -0
- data/lib/generators/rails_config/templates/settings/development.yml +0 -0
- data/lib/generators/rails_config/templates/settings/production.yml +0 -0
- data/lib/generators/rails_config/templates/settings/test.yml +0 -0
- data/lib/rails_config.rb +64 -0
- data/lib/rails_config/deep_merge.rb +32 -0
- data/lib/rails_config/engine.rb +5 -0
- data/lib/rails_config/integration/rails.rb +34 -0
- data/lib/rails_config/integration/sinatra.rb +26 -0
- data/lib/rails_config/options.rb +118 -0
- data/lib/rails_config/rack/reloader.rb +15 -0
- data/lib/rails_config/railtie.rb +9 -0
- data/lib/rails_config/sources/yaml_source.rb +26 -0
- data/lib/rails_config/tasks.rb +59 -0
- data/lib/rails_config/tasks/heroku.rake +8 -0
- data/lib/rails_config/version.rb +3 -0
- data/rails_config.gemspec +40 -0
- data/spec/app/rails_3/Rakefile +7 -0
- data/spec/app/rails_3/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_3/app/assets/stylesheets/application.css +13 -0
- data/spec/app/rails_3/app/controllers/application_controller.rb +3 -0
- data/spec/app/rails_3/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_3/app/models/.gitkeep +0 -0
- data/spec/app/rails_3/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_3/bin/bundle +3 -0
- data/spec/app/rails_3/bin/rails +4 -0
- data/spec/app/rails_3/bin/rake +4 -0
- data/spec/app/rails_3/config.ru +4 -0
- data/spec/app/rails_3/config/application.rb +29 -0
- data/spec/app/rails_3/config/boot.rb +5 -0
- data/spec/app/rails_3/config/database.yml +25 -0
- data/spec/app/rails_3/config/environment.rb +5 -0
- data/spec/app/rails_3/config/environments/development.rb +42 -0
- data/spec/app/rails_3/config/environments/production.rb +72 -0
- data/spec/app/rails_3/config/environments/test.rb +42 -0
- data/spec/app/rails_3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_3/config/initializers/inflections.rb +15 -0
- data/spec/app/rails_3/config/initializers/mime_types.rb +5 -0
- data/spec/app/rails_3/config/initializers/secret_token.rb +7 -0
- data/spec/app/rails_3/config/initializers/session_store.rb +8 -0
- data/spec/app/rails_3/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_3/config/locales/en.yml +5 -0
- data/spec/app/rails_3/config/routes.rb +2 -0
- data/spec/app/rails_3/config/settings.yml +7 -0
- data/spec/app/rails_3/db/.gitkeep +0 -0
- data/spec/app/rails_3/public/404.html +26 -0
- data/spec/app/rails_3/public/422.html +26 -0
- data/spec/app/rails_3/public/500.html +25 -0
- data/spec/app/rails_3/script/rails +6 -0
- data/spec/app/rails_4.1/Rakefile +6 -0
- data/spec/app/rails_4.1/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_4.1/app/assets/stylesheets/application.css +15 -0
- data/spec/app/rails_4.1/app/controllers/application_controller.rb +5 -0
- data/spec/app/rails_4.1/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_4.1/app/models/.keep +0 -0
- data/spec/app/rails_4.1/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_4.1/bin/bundle +3 -0
- data/spec/app/rails_4.1/bin/rails +4 -0
- data/spec/app/rails_4.1/bin/rake +4 -0
- data/spec/app/rails_4.1/config.ru +4 -0
- data/spec/app/rails_4.1/config/application.rb +27 -0
- data/spec/app/rails_4.1/config/boot.rb +5 -0
- data/spec/app/rails_4.1/config/database.yml +25 -0
- data/spec/app/rails_4.1/config/environment.rb +5 -0
- data/spec/app/rails_4.1/config/environments/development.rb +42 -0
- data/spec/app/rails_4.1/config/environments/production.rb +88 -0
- data/spec/app/rails_4.1/config/environments/test.rb +44 -0
- data/spec/app/rails_4.1/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_4.1/config/initializers/cookies_serializer.rb +3 -0
- data/spec/app/rails_4.1/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/app/rails_4.1/config/initializers/inflections.rb +16 -0
- data/spec/app/rails_4.1/config/initializers/mime_types.rb +4 -0
- data/spec/app/rails_4.1/config/initializers/session_store.rb +3 -0
- data/spec/app/rails_4.1/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_4.1/config/locales/en.yml +23 -0
- data/spec/app/rails_4.1/config/routes.rb +2 -0
- data/spec/app/rails_4.1/config/secrets.yml +22 -0
- data/spec/app/rails_4.1/config/settings.yml +7 -0
- data/spec/app/rails_4.1/db/.keep +0 -0
- data/spec/app/rails_4.1/public/404.html +67 -0
- data/spec/app/rails_4.1/public/422.html +67 -0
- data/spec/app/rails_4.1/public/500.html +66 -0
- data/spec/app/rails_4/Rakefile +6 -0
- data/spec/app/rails_4/app/assets/javascripts/application.js +13 -0
- data/spec/app/rails_4/app/assets/stylesheets/application.css +13 -0
- data/spec/app/rails_4/app/controllers/application_controller.rb +5 -0
- data/spec/app/rails_4/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_4/app/models/.keep +0 -0
- data/spec/app/rails_4/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_4/bin/bundle +3 -0
- data/spec/app/rails_4/bin/rails +4 -0
- data/spec/app/rails_4/bin/rake +4 -0
- data/spec/app/rails_4/config.ru +4 -0
- data/spec/app/rails_4/config/application.rb +27 -0
- data/spec/app/rails_4/config/boot.rb +5 -0
- data/spec/app/rails_4/config/database.yml +25 -0
- data/spec/app/rails_4/config/environment.rb +5 -0
- data/spec/app/rails_4/config/environments/development.rb +34 -0
- data/spec/app/rails_4/config/environments/production.rb +85 -0
- data/spec/app/rails_4/config/environments/test.rb +41 -0
- data/spec/app/rails_4/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_4/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/app/rails_4/config/initializers/inflections.rb +16 -0
- data/spec/app/rails_4/config/initializers/mime_types.rb +5 -0
- data/spec/app/rails_4/config/initializers/secret_token.rb +12 -0
- data/spec/app/rails_4/config/initializers/session_store.rb +3 -0
- data/spec/app/rails_4/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_4/config/locales/en.yml +23 -0
- data/spec/app/rails_4/config/routes.rb +2 -0
- data/spec/app/rails_4/config/settings.yml +7 -0
- data/spec/app/rails_4/db/.keep +0 -0
- data/spec/app/rails_4/public/404.html +58 -0
- data/spec/app/rails_4/public/422.html +58 -0
- data/spec/app/rails_4/public/500.html +57 -0
- data/spec/fixtures/bool_override/config1.yml +2 -0
- data/spec/fixtures/bool_override/config2.yml +2 -0
- data/spec/fixtures/custom_types/hash.yml +7 -0
- data/spec/fixtures/deep_merge/config1.yml +28 -0
- data/spec/fixtures/deep_merge/config2.yml +28 -0
- data/spec/fixtures/deep_merge2/config1.yml +3 -0
- data/spec/fixtures/deep_merge2/config2.yml +2 -0
- data/spec/fixtures/development.yml +4 -0
- data/spec/fixtures/empty1.yml +0 -0
- data/spec/fixtures/empty2.yml +0 -0
- data/spec/fixtures/env/settings.yml +4 -0
- data/spec/fixtures/malformed.yml +6 -0
- data/spec/fixtures/settings.yml +21 -0
- data/spec/fixtures/settings2.yml +1 -0
- data/spec/fixtures/with_erb.yml +4 -0
- data/spec/rails_config_helper.rb +22 -0
- data/spec/rails_config_spec.rb +311 -0
- data/spec/sources/yaml_source_spec.rb +77 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/support/shared_contexts/rake.rb +8 -0
- data/spec/tasks/db_spec.rb +9 -0
- metadata +476 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d0dab090b5c539d48bbb84dd67f60382f90d1e3
|
4
|
+
data.tar.gz: 514fb195b79157f83cb69589105fbd063caced7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e07b93d5cdddf4860add6d4e14621c709a124225cd3aaa6570a7c5230b93c648c72ea542e5a9914857fb57e3cc35c92fab47abfc7a157679ceccb5500776479
|
7
|
+
data.tar.gz: 986fb806117949b1bc78b99b2b253b289c9c1cb02998437285a9be98319e620917942cf586b521b97bc2565cc312d94298818c7ed091732faccec39d19a806d0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails_config
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# 0.5.0.beta1
|
2
|
+
|
3
|
+
* Made rails_config work without Rails as a hard dependency ([#86](https://github.com/railsjedi/rails_config/issues/86 [#88](https://github.com/railsjedi/rails_config/issues/88)
|
4
|
+
* Fix generate error when .gitignore is missing ([#85](https://github.com/railsjedi/rails_config/issues/85))
|
5
|
+
* Fix deprecation warning on File.exists? ([#81](https://github.com/railsjedi/rails_config/issues/81))
|
6
|
+
* Add a shortcut method for setting files ([#67](https://github.com/railsjedi/rails_config/issues/67))
|
7
|
+
* Improve YAMLSource load error message by outputting offending file path ([#88](https://github.com/railsjedi/rails_config/issues/88))
|
8
|
+
|
9
|
+
# 0.4.2
|
10
|
+
* Ability to specify the app name when calling the Heroku rake task ([#75](https://github.com/railsjedi/rails_config/issues/75))
|
11
|
+
|
12
|
+
# 0.4.1
|
13
|
+
|
14
|
+
* Fixed compatibility with Rails 4.1 ([#72](https://github.com/railsjedi/rails_config/issues/72))
|
15
|
+
* Testing suite verifies compatibility with Rails 3.2, 4.0 and 4.1
|
16
|
+
|
17
|
+
# 0.4.0
|
18
|
+
|
19
|
+
* Compatibility with Heroku ([#64](https://github.com/railsjedi/rails_config/issues/64))
|
20
|
+
|
21
|
+
# 0.3.4
|
22
|
+
|
23
|
+
* Expose Settings in application.rb, so you don't have to duplicate configuration for each environment file ([#59](https://github.com/railsjedi/rails_config/issues/59))
|
24
|
+
* Adding support for Rails 4.1.0.rc ([#70](https://github.com/railsjedi/rails_config/issues/70))
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2010-2014 Jacques Crocker, Fred Wu, Piotr Kuczynski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
23
|
+
|
24
|
+
Third-party materials and licenses:
|
25
|
+
|
26
|
+
* RailsConfig contains Deep Merge (deep_merge.rb) which is governed by the MIT license
|
27
|
+
Copyright (C) 2008 Steve Midgley
|
data/README.md
ADDED
@@ -0,0 +1,317 @@
|
|
1
|
+
# RailsConfig
|
2
|
+
|
3
|
+
THIS IS A FORK!
|
4
|
+
|
5
|
+
This variant of the `rails_config` gem uses a much easier to understand and
|
6
|
+
therefore easier to use and more reliable deep-merge strategy. The key
|
7
|
+
property can be summarized in the following sentence:
|
8
|
+
|
9
|
+
** Values which are to be merged in and are not maps/hashes always overwrite
|
10
|
+
exiting values. **
|
11
|
+
|
12
|
+
|
13
|
+
The formal descriptions reads as follows:
|
14
|
+
|
15
|
+
|
16
|
+
Let `M1` and `M2` be a maps, and let `M` be the result of `deep_merge M1 M2`
|
17
|
+
Then the following holds true:
|
18
|
+
|
19
|
+
1. If the key `k` with the value `v1` is present in `M1` but not in `M2`, then
|
20
|
+
the key value pair `(k,v1)` is be present in `M`.
|
21
|
+
|
22
|
+
2. If the key `k` with the value `v2` is present in `M2` but not in `M1`, then
|
23
|
+
the key value pair `(k,v2)` is be present in `M`.
|
24
|
+
|
25
|
+
3. If `k` is present in `M1` and `M2`
|
26
|
+
|
27
|
+
1. and `v1` and `v2` are both maps, then the pair `(k, deep_merge v1 v2 )` is present in `M`.
|
28
|
+
|
29
|
+
2. otherwise the pair `(k,v2)` is present in `M`.
|
30
|
+
|
31
|
+
|
32
|
+
The implementation comprises about 30 lines whereas the original one extends to
|
33
|
+
about 180 lines including some rather diffuse comments.
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
## Summary
|
38
|
+
|
39
|
+
RailsConfig helps you easily manage environment specific Rails settings in an easy and usable manner
|
40
|
+
|
41
|
+
## Features
|
42
|
+
|
43
|
+
* simple YAML config files
|
44
|
+
* config files support ERB
|
45
|
+
* config files support inheritance
|
46
|
+
* access config information via convenient object member notation
|
47
|
+
|
48
|
+
## Compatibility
|
49
|
+
|
50
|
+
* Rails 3.x and 4.x
|
51
|
+
* Padrino
|
52
|
+
* Sinatra
|
53
|
+
|
54
|
+
For older versions of Rails and other Ruby apps, use [AppConfig](http://github.com/fredwu/app_config).
|
55
|
+
|
56
|
+
## Installing on Rails 3 or 4
|
57
|
+
|
58
|
+
Add this to your `Gemfile`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem "rails_config"
|
62
|
+
```
|
63
|
+
|
64
|
+
## Installing on Padrino
|
65
|
+
|
66
|
+
Add this to your `Gemfile`:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
gem "rails_config"
|
70
|
+
```
|
71
|
+
|
72
|
+
in your app.rb, you'll also need to register RailsConfig
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
register RailsConfig
|
76
|
+
```
|
77
|
+
|
78
|
+
## Installing on Sinatra
|
79
|
+
|
80
|
+
Add this to your `Gemfile`:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
gem "rails_config"
|
84
|
+
```
|
85
|
+
|
86
|
+
in your app, you'll need to register RailsConfig. You'll also need to give it a root so it can find the config files.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
set :root, File.dirname(__FILE__)
|
90
|
+
register RailsConfig
|
91
|
+
```
|
92
|
+
|
93
|
+
It's also possible to initialize it manually within your configure block if you want to just give it some yml paths to load from.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
RailsConfig.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
97
|
+
```
|
98
|
+
|
99
|
+
## Customizing RailsConfig
|
100
|
+
|
101
|
+
You may customize the behavior of RailsConfig by generating an initializer file:
|
102
|
+
|
103
|
+
rails g rails_config:install
|
104
|
+
|
105
|
+
This will generate `config/initializers/rails_config.rb` with a set of default settings as well as to generate a set of default settings files:
|
106
|
+
|
107
|
+
config/settings.yml
|
108
|
+
config/settings/development.yml
|
109
|
+
config/settings/production.yml
|
110
|
+
config/settings/test.yml
|
111
|
+
|
112
|
+
## Accessing the Settings object
|
113
|
+
|
114
|
+
After installing this plugin, the `Settings` object will be available globally. Entries are accessed via object member notation:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
Settings.my_config_entry
|
118
|
+
```
|
119
|
+
|
120
|
+
Nested entries are supported:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
Settings.my_section.some_entry
|
124
|
+
```
|
125
|
+
|
126
|
+
Alternatively, you can also use the `[]` operator if you don't know which exact setting you need to access ahead of time.
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
# All the following are equivalent to Settings.my_section.some_entry
|
130
|
+
Settings.my_section[:some_entry]
|
131
|
+
Settings.my_section['some_entry']
|
132
|
+
Settings[:my_section][:some_entry]
|
133
|
+
```
|
134
|
+
|
135
|
+
If you have set a different constant name for the object in the initializer file, use that instead.
|
136
|
+
|
137
|
+
## Common config file
|
138
|
+
|
139
|
+
Config entries are compiled from:
|
140
|
+
|
141
|
+
config/settings.yml
|
142
|
+
config/settings/#{environment}.yml
|
143
|
+
config/environments/#{environment}.yml
|
144
|
+
|
145
|
+
config/settings.local.yml
|
146
|
+
config/settings/#{environment}.local.yml
|
147
|
+
config/environments/#{environment}.local.yml
|
148
|
+
|
149
|
+
Settings defined in files that are lower in the list override settings higher.
|
150
|
+
|
151
|
+
### Reloading settings
|
152
|
+
|
153
|
+
You can reload the Settings object at any time by running `Settings.reload!`.
|
154
|
+
|
155
|
+
### Reloading settings and config files
|
156
|
+
|
157
|
+
You can also reload the `Settings` object from different config files at runtime.
|
158
|
+
|
159
|
+
For example, in your tests if you want to test the production settings, you can:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
Rails.env = "production"
|
163
|
+
Settings.reload_from_files(
|
164
|
+
Rails.root.join("config", "settings.yml").to_s,
|
165
|
+
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
166
|
+
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
167
|
+
)
|
168
|
+
```
|
169
|
+
|
170
|
+
### Environment specific config files
|
171
|
+
|
172
|
+
You can have environment specific config files. Environment specific config entries take precedence over common config entries.
|
173
|
+
|
174
|
+
Example development environment config file:
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
#{Rails.root}/config/environments/development.yml
|
178
|
+
```
|
179
|
+
|
180
|
+
Example production environment config file:
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
#{Rails.root}/config/environments/production.yml
|
184
|
+
```
|
185
|
+
|
186
|
+
### Developer specific config files
|
187
|
+
|
188
|
+
If you want to have local settings, specific to your machine or development environment,
|
189
|
+
you can use the following files, which are automatically `.gitignored` :
|
190
|
+
|
191
|
+
Rails.root.join("config", "settings.local.yml").to_s,
|
192
|
+
Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
|
193
|
+
Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
|
194
|
+
|
195
|
+
|
196
|
+
### Adding sources at Runtime
|
197
|
+
|
198
|
+
You can add new YAML config files at runtime. Just use:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
Settings.add_source!("/path/to/source.yml")
|
202
|
+
Settings.reload!
|
203
|
+
```
|
204
|
+
|
205
|
+
This will use the given source.yml file and use its settings to overwrite any previous ones.
|
206
|
+
|
207
|
+
One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent per developer). Then I create a new initializer in `config/initializers/add_local_config.rb` with the contents
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
Settings.add_source!("#{Rails.root}/config/settings/local.yml")
|
211
|
+
Settings.reload!
|
212
|
+
```
|
213
|
+
|
214
|
+
> Note: this is an example usage, it is easier to just use the default local files `settings.local.yml, settings/#{Rails.env}.local.yml and environments/#{Rails.env}.local.yml`
|
215
|
+
> for your developer specific settings.
|
216
|
+
|
217
|
+
## Embedded Ruby (ERB)
|
218
|
+
|
219
|
+
Embedded Ruby is allowed in the configuration files. See examples below.
|
220
|
+
|
221
|
+
## Accessing Configuration Settings
|
222
|
+
|
223
|
+
Consider the two following config files.
|
224
|
+
|
225
|
+
#{Rails.root}/config/settings.yml:
|
226
|
+
|
227
|
+
```yaml
|
228
|
+
size: 1
|
229
|
+
server: google.com
|
230
|
+
```
|
231
|
+
|
232
|
+
#{Rails.root}/config/environments/development.yml:
|
233
|
+
|
234
|
+
```yaml
|
235
|
+
size: 2
|
236
|
+
computed: <%= 1 + 2 + 3 %>
|
237
|
+
section:
|
238
|
+
size: 3
|
239
|
+
servers: [ {name: yahoo.com}, {name: amazon.com} ]
|
240
|
+
```
|
241
|
+
|
242
|
+
Notice that the environment specific config entries overwrite the common entries.
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
Settings.size # => 2
|
246
|
+
Settings.server # => google.com
|
247
|
+
```
|
248
|
+
|
249
|
+
Notice the embedded Ruby.
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
Settings.computed # => 6
|
253
|
+
```
|
254
|
+
|
255
|
+
Notice that object member notation is maintained even in nested entries.
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
Settings.section.size # => 3
|
259
|
+
```
|
260
|
+
|
261
|
+
Notice array notation and object member notation is maintained.
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
Settings.section.servers[0].name # => yahoo.com
|
265
|
+
Settings.section.servers[1].name # => amazon.com
|
266
|
+
```
|
267
|
+
|
268
|
+
## Working with Heroku
|
269
|
+
|
270
|
+
Heroku uses ENV object to store sensitive settings which are like the local files described above. You cannot upload such files to Heroku because it's ephemeral filesystem gets recreated from the git sources on each instance refresh.
|
271
|
+
|
272
|
+
To use rails_config with Heroku just set the `use_env` var to `true` in your `config/initializers/rails_config.rb` file. Eg:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
RailsConfig.setup do |config|
|
276
|
+
config.const_name = 'AppSettings'
|
277
|
+
config.use_env = true
|
278
|
+
end
|
279
|
+
```
|
280
|
+
|
281
|
+
Now rails_config would read values from the ENV object to the settings. For the example above it would look for keys starting with 'AppSettings'. Eg:
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
ENV['AppSettings.section.size'] = 1
|
285
|
+
ENV['AppSettings.section.server'] = 'google.com'
|
286
|
+
```
|
287
|
+
|
288
|
+
It won't work with arrays, though.
|
289
|
+
|
290
|
+
To upload your local values to Heroku you could ran `bundle exec rake rails_config:heroku`.
|
291
|
+
|
292
|
+
|
293
|
+
## Contributing
|
294
|
+
|
295
|
+
Bootstrap
|
296
|
+
|
297
|
+
```bash
|
298
|
+
$ appraisal install
|
299
|
+
```
|
300
|
+
|
301
|
+
Running the test suite
|
302
|
+
|
303
|
+
```bash
|
304
|
+
$ appraisal rspec
|
305
|
+
```
|
306
|
+
|
307
|
+
|
308
|
+
## Authors
|
309
|
+
|
310
|
+
* [Jacques Crocker](http://github.com/railsjedi)
|
311
|
+
* [Fred Wu](http://github.com/fredwu)
|
312
|
+
* [Piotr Kuczynski](http://github.com/pkuczynski)
|
313
|
+
* Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
|
314
|
+
|
315
|
+
## License
|
316
|
+
|
317
|
+
RailsConfig is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
rescue LoadError
|
9
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
##
|
14
|
+
# Testing
|
15
|
+
#
|
16
|
+
require "rspec"
|
17
|
+
require "rspec/core/rake_task"
|
18
|
+
|
19
|
+
RSpec::Core::RakeTask.new(:spec)
|
20
|
+
|
21
|
+
task :default => :spec
|
22
|
+
|
23
|
+
# Test for multiple Rails scenarios
|
24
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
25
|
+
require "appraisal"
|
26
|
+
|
27
|
+
task :default => :appraisal
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
##
|
32
|
+
# Documentation
|
33
|
+
#
|
34
|
+
require 'rdoc/task'
|
35
|
+
|
36
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = "RailsConfig #{RailsConfig::VERSION}"
|
39
|
+
rdoc.options << '--line-numbers'
|
40
|
+
rdoc.rdoc_files.include('README.*')
|
41
|
+
rdoc.rdoc_files.include('CHANGELOG.*')
|
42
|
+
rdoc.rdoc_files.include('LICENSE.*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Rails Application
|
48
|
+
#
|
49
|
+
|
50
|
+
# APP_RAKEFILE = File.expand_path("../spec/app/rails/Rakefile", __FILE__)
|
51
|
+
# load 'rails/tasks/engine.rake'
|
52
|
+
|
53
|
+
|