config 0.0.1 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +6 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +23 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +6 -0
- data/LICENSE.md +27 -0
- data/README.md +315 -0
- data/Rakefile +42 -0
- data/config.gemspec +46 -0
- data/gemfiles/rails_3.gemfile +7 -0
- data/gemfiles/rails_4.1.gemfile +7 -0
- data/gemfiles/rails_4.2.gemfile +7 -0
- data/gemfiles/rails_4.gemfile +7 -0
- data/lib/config.rb +64 -0
- data/lib/config/engine.rb +5 -0
- data/lib/config/integration/rails.rb +36 -0
- data/lib/config/integration/sinatra.rb +26 -0
- data/lib/config/options.rb +157 -0
- data/lib/config/rack/reloader.rb +15 -0
- data/lib/config/railtie.rb +9 -0
- data/lib/config/sources/yaml_source.rb +26 -0
- data/lib/config/tasks.rb +59 -0
- data/lib/config/tasks/heroku.rake +8 -0
- data/lib/config/version.rb +3 -0
- data/lib/generators/config/install_generator.rb +32 -0
- data/lib/generators/config/templates/rails_config.rb +3 -0
- data/lib/generators/config/templates/settings.local.yml +0 -0
- data/lib/generators/config/templates/settings.yml +0 -0
- data/lib/generators/config/templates/settings/development.yml +0 -0
- data/lib/generators/config/templates/settings/production.yml +0 -0
- data/lib/generators/config/templates/settings/test.yml +0 -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.2/Rakefile +6 -0
- data/spec/app/rails_4.2/app/assets/images/.keep +0 -0
- data/spec/app/rails_4.2/app/assets/javascripts/application.js +16 -0
- data/spec/app/rails_4.2/app/assets/stylesheets/application.css +15 -0
- data/spec/app/rails_4.2/app/controllers/application_controller.rb +5 -0
- data/spec/app/rails_4.2/app/controllers/concerns/.keep +0 -0
- data/spec/app/rails_4.2/app/helpers/application_helper.rb +2 -0
- data/spec/app/rails_4.2/app/mailers/.keep +0 -0
- data/spec/app/rails_4.2/app/models/.keep +0 -0
- data/spec/app/rails_4.2/app/models/concerns/.keep +0 -0
- data/spec/app/rails_4.2/app/views/layouts/application.html.erb +14 -0
- data/spec/app/rails_4.2/bin/bundle +3 -0
- data/spec/app/rails_4.2/bin/rails +8 -0
- data/spec/app/rails_4.2/bin/rake +8 -0
- data/spec/app/rails_4.2/bin/setup +29 -0
- data/spec/app/rails_4.2/bin/spring +15 -0
- data/spec/app/rails_4.2/config.ru +4 -0
- data/spec/app/rails_4.2/config/application.rb +31 -0
- data/spec/app/rails_4.2/config/boot.rb +3 -0
- data/spec/app/rails_4.2/config/database.yml +25 -0
- data/spec/app/rails_4.2/config/environment.rb +5 -0
- data/spec/app/rails_4.2/config/environments/development.rb +41 -0
- data/spec/app/rails_4.2/config/environments/production.rb +79 -0
- data/spec/app/rails_4.2/config/environments/test.rb +42 -0
- data/spec/app/rails_4.2/config/initializers/assets.rb +11 -0
- data/spec/app/rails_4.2/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/app/rails_4.2/config/initializers/cookies_serializer.rb +3 -0
- data/spec/app/rails_4.2/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/app/rails_4.2/config/initializers/inflections.rb +16 -0
- data/spec/app/rails_4.2/config/initializers/mime_types.rb +4 -0
- data/spec/app/rails_4.2/config/initializers/session_store.rb +3 -0
- data/spec/app/rails_4.2/config/initializers/wrap_parameters.rb +14 -0
- data/spec/app/rails_4.2/config/locales/en.yml +23 -0
- data/spec/app/rails_4.2/config/routes.rb +56 -0
- data/spec/app/rails_4.2/config/secrets.yml +22 -0
- data/spec/app/rails_4.2/config/settings.yml +7 -0
- data/spec/app/rails_4.2/db/seeds.rb +7 -0
- data/spec/app/rails_4.2/public/404.html +67 -0
- data/spec/app/rails_4.2/public/422.html +67 -0
- data/spec/app/rails_4.2/public/500.html +66 -0
- data/spec/app/rails_4.2/public/favicon.ico +0 -0
- data/spec/app/rails_4.2/public/robots.txt +5 -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/config_spec.rb +317 -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/reserved_keywords.yml +2 -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/options_spec.rb +84 -0
- data/spec/sources/yaml_source_spec.rb +77 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/support/rails_config_helper.rb +22 -0
- data/spec/support/shared_contexts/rake.rb +8 -0
- data/spec/tasks/db_spec.rb +9 -0
- metadata +580 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 742d8178dc47ffe14f3633331c1f6ddad2b8e2ff
|
4
|
+
data.tar.gz: 02001b77f2146124b531f0578eaa99362f62ebeb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c80b416f608bcf7ae0cac1163f26241f4d723bc3034d15967b466ae07eb07c102ac89930154f117189e784f81d2c37a517d337a4b2c3bab976ddef528d4f4a55
|
7
|
+
data.tar.gz: added79d112c09feae7211a5afec99bbda1f75412651dc7df3434242a737ebb79a0eaa5c39346fd2f041eb25ea0ce6427c1ec22ff4ffc5b063d564f079e1496f
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
config
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.6
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
sudo: false
|
4
|
+
rvm:
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.6
|
7
|
+
- 2.2.2
|
8
|
+
gemfile:
|
9
|
+
- gemfiles/rails_3.gemfile
|
10
|
+
- gemfiles/rails_4.gemfile
|
11
|
+
- gemfiles/rails_4.1.gemfile
|
12
|
+
- gemfiles/rails_4.2.gemfile
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
- rvm: 2.2.2
|
16
|
+
gemfile: gemfiles/rails_3.gemfile
|
17
|
+
before_install:
|
18
|
+
- gem install bundler
|
19
|
+
script:
|
20
|
+
- bundle exec rspec
|
21
|
+
addons:
|
22
|
+
code_climate:
|
23
|
+
repo_token: 88c5452d41835351d037ce45781e2e88b1c0bdc8508ee9722746bac633bba88e
|
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# 0.5.0.beta1
|
2
|
+
|
3
|
+
* Ability to use in Settings file keywords reserved for OpenStruct: select, collect ([#95](https://github.com/railsjedi/config/issues/95))
|
4
|
+
* Made config work without Rails as a hard dependency ([#86](https://github.com/railsjedi/config/issues/86), [#88](https://github.com/railsjedi/config/issues/88))
|
5
|
+
* Fix generate error when .gitignore is missing ([#85](https://github.com/railsjedi/config/issues/85))
|
6
|
+
* Fix deprecation warning on File.exists? ([#81](https://github.com/railsjedi/config/issues/81))
|
7
|
+
* Add a shortcut method for setting files ([#67](https://github.com/railsjedi/config/issues/67))
|
8
|
+
* Improve YAMLSource load error message by outputting offending file path ([#88](https://github.com/railsjedi/config/issues/88))
|
9
|
+
|
10
|
+
# 0.4.2
|
11
|
+
* Ability to specify the app name when calling the Heroku rake task ([#75](https://github.com/railsjedi/config/issues/75))
|
12
|
+
|
13
|
+
# 0.4.1
|
14
|
+
|
15
|
+
* Fixed compatibility with Rails 4.1 ([#72](https://github.com/railsjedi/config/issues/72))
|
16
|
+
* Testing suite verifies compatibility with Rails 3.2, 4.0 and 4.1
|
17
|
+
|
18
|
+
# 0.4.0
|
19
|
+
|
20
|
+
* Compatibility with Heroku ([#64](https://github.com/railsjedi/config/issues/64))
|
21
|
+
|
22
|
+
# 0.3.4
|
23
|
+
|
24
|
+
* Expose Settings in application.rb, so you don't have to duplicate configuration for each environment file ([#59](https://github.com/railsjedi/config/issues/59))
|
25
|
+
* Adding support for Rails 4.1.0.rc ([#70](https://github.com/railsjedi/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
|
+
* Config 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,315 @@
|
|
1
|
+
[![Build Status](https://api.travis-ci.org/railsconfig/config.svg?branch=master)](http://travis-ci.org/railsconfig/config)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/config.svg)](http://badge.fury.io/rb/config)
|
3
|
+
[![Dependency Status](https://gemnasium.com/railsconfig/config.svg)](https://gemnasium.com/railsconfig/config)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/railsconfig/config/badges/gpa.svg)](https://codeclimate.com/github/railsconfig/config)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/railsconfig/config/badges/coverage.svg)](https://codeclimate.com/github/railsconfig/config/coverage)
|
6
|
+
|
7
|
+
# Config
|
8
|
+
|
9
|
+
## Summary
|
10
|
+
|
11
|
+
Config helps you easily manage environment specific settings in an easy and usable manner.
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
- simple YAML config files
|
16
|
+
- config files support ERB
|
17
|
+
- config files support inheritance
|
18
|
+
- access config information via convenient object member notation
|
19
|
+
|
20
|
+
## Compatibility
|
21
|
+
|
22
|
+
- Ruby 2.x
|
23
|
+
- Rails 3.x and 4.x
|
24
|
+
- Padrino
|
25
|
+
- Sinatra
|
26
|
+
|
27
|
+
For older versions of Rails and other Ruby apps, use [AppConfig](http://github.com/fredwu/app_config).
|
28
|
+
|
29
|
+
## Installing on Rails 3 or 4
|
30
|
+
|
31
|
+
Add this to your `Gemfile`:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem "config"
|
35
|
+
```
|
36
|
+
|
37
|
+
If you want to use Settings before rails application initialization process you can load Config railtie manually:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
module Appname
|
41
|
+
class Application < Rails::Application
|
42
|
+
|
43
|
+
Bundler.require(*Rails.groups)
|
44
|
+
Config::Integration::Rails::Railtie.preload
|
45
|
+
|
46
|
+
# ...
|
47
|
+
|
48
|
+
config.time_zone = Settings.time_zone
|
49
|
+
|
50
|
+
# ...
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## Installing on Padrino
|
57
|
+
|
58
|
+
Add this to your `Gemfile`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem "config"
|
62
|
+
```
|
63
|
+
|
64
|
+
in your app.rb, you'll also need to register Config
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
register Config
|
68
|
+
```
|
69
|
+
|
70
|
+
## Installing on Sinatra
|
71
|
+
|
72
|
+
Add this to your `Gemfile`:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
gem "config"
|
76
|
+
```
|
77
|
+
|
78
|
+
in your app, you'll need to register Config. You'll also need to give it a root so it can find the config files.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
set :root, File.dirname(__FILE__)
|
82
|
+
register Config
|
83
|
+
```
|
84
|
+
|
85
|
+
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.
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
89
|
+
```
|
90
|
+
|
91
|
+
## Customizing Config
|
92
|
+
|
93
|
+
You may customize the behavior of Config by generating an initializer file:
|
94
|
+
|
95
|
+
rails g config:install
|
96
|
+
|
97
|
+
This will generate `config/initializers/config.rb` with a set of default settings as well as to generate a set of default settings files:
|
98
|
+
|
99
|
+
config/settings.yml
|
100
|
+
config/settings/development.yml
|
101
|
+
config/settings/production.yml
|
102
|
+
config/settings/test.yml
|
103
|
+
|
104
|
+
## Accessing the Settings object
|
105
|
+
|
106
|
+
After installing this plugin, the `Settings` object will be available globally. Entries are accessed via object member notation:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
Settings.my_config_entry
|
110
|
+
```
|
111
|
+
|
112
|
+
Nested entries are supported:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
Settings.my_section.some_entry
|
116
|
+
```
|
117
|
+
|
118
|
+
Alternatively, you can also use the `[]` operator if you don't know which exact setting you need to access ahead of time.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# All the following are equivalent to Settings.my_section.some_entry
|
122
|
+
Settings.my_section[:some_entry]
|
123
|
+
Settings.my_section['some_entry']
|
124
|
+
Settings[:my_section][:some_entry]
|
125
|
+
```
|
126
|
+
|
127
|
+
If you have set a different constant name for the object in the initializer file, use that instead.
|
128
|
+
|
129
|
+
## Common config file
|
130
|
+
|
131
|
+
Config entries are compiled from:
|
132
|
+
|
133
|
+
config/settings.yml
|
134
|
+
config/settings/#{environment}.yml
|
135
|
+
config/environments/#{environment}.yml
|
136
|
+
|
137
|
+
config/settings.local.yml
|
138
|
+
config/settings/#{environment}.local.yml
|
139
|
+
config/environments/#{environment}.local.yml
|
140
|
+
|
141
|
+
Settings defined in files that are lower in the list override settings higher.
|
142
|
+
|
143
|
+
### Reloading settings
|
144
|
+
|
145
|
+
You can reload the Settings object at any time by running `Settings.reload!`.
|
146
|
+
|
147
|
+
### Reloading settings and config files
|
148
|
+
|
149
|
+
You can also reload the `Settings` object from different config files at runtime.
|
150
|
+
|
151
|
+
For example, in your tests if you want to test the production settings, you can:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
Rails.env = "production"
|
155
|
+
Settings.reload_from_files(
|
156
|
+
Rails.root.join("config", "settings.yml").to_s,
|
157
|
+
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
158
|
+
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
159
|
+
)
|
160
|
+
```
|
161
|
+
|
162
|
+
### Environment specific config files
|
163
|
+
|
164
|
+
You can have environment specific config files. Environment specific config entries take precedence over common config entries.
|
165
|
+
|
166
|
+
Example development environment config file:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
#{Rails.root}/config/environments/development.yml
|
170
|
+
```
|
171
|
+
|
172
|
+
Example production environment config file:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
#{Rails.root}/config/environments/production.yml
|
176
|
+
```
|
177
|
+
|
178
|
+
### Developer specific config files
|
179
|
+
|
180
|
+
If you want to have local settings, specific to your machine or development environment,
|
181
|
+
you can use the following files, which are automatically `.gitignored` :
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
Rails.root.join("config", "settings.local.yml").to_s,
|
185
|
+
Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
|
186
|
+
Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
|
187
|
+
```
|
188
|
+
|
189
|
+
### Adding sources at Runtime
|
190
|
+
|
191
|
+
You can add new YAML config files at runtime. Just use:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
Settings.add_source!("/path/to/source.yml")
|
195
|
+
Settings.reload!
|
196
|
+
```
|
197
|
+
|
198
|
+
This will use the given source.yml file and use its settings to overwrite any previous ones.
|
199
|
+
|
200
|
+
On the other hand, you can prepend a YML file to the list of configuration files:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
Settings.prepend_source!("/path/to/source.yml")
|
204
|
+
Settings.reload!
|
205
|
+
```
|
206
|
+
|
207
|
+
This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings will be overwritten by any other configuration file.
|
208
|
+
This is especially useful if you want to define defaults.
|
209
|
+
|
210
|
+
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
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
Settings.add_source!("#{Rails.root}/config/settings/local.yml")
|
214
|
+
Settings.reload!
|
215
|
+
```
|
216
|
+
|
217
|
+
> 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` for your developer specific settings.
|
218
|
+
|
219
|
+
## Embedded Ruby (ERB)
|
220
|
+
|
221
|
+
Embedded Ruby is allowed in the configuration files. See examples below.
|
222
|
+
|
223
|
+
## Accessing Configuration Settings
|
224
|
+
|
225
|
+
Consider the two following config files.
|
226
|
+
|
227
|
+
* ```#{Rails.root}/config/settings.yml```
|
228
|
+
```yaml
|
229
|
+
size: 1
|
230
|
+
server: google.com
|
231
|
+
```
|
232
|
+
|
233
|
+
* ```#{Rails.root}/config/environments/development.yml```
|
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 config with Heroku just set the `use_env` var to `true` in your `config/initializers/config.rb` file. Eg:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
Config.setup do |config|
|
276
|
+
config.const_name = 'AppSettings'
|
277
|
+
config.use_env = true
|
278
|
+
end
|
279
|
+
```
|
280
|
+
|
281
|
+
Now 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 config:heroku`.
|
291
|
+
|
292
|
+
## Contributing
|
293
|
+
|
294
|
+
Bootstrap
|
295
|
+
|
296
|
+
```bash
|
297
|
+
$ appraisal install
|
298
|
+
```
|
299
|
+
|
300
|
+
Running the test suite
|
301
|
+
|
302
|
+
```bash
|
303
|
+
$ appraisal rspec
|
304
|
+
```
|
305
|
+
|
306
|
+
## Authors
|
307
|
+
|
308
|
+
* [Jacques Crocker](http://github.com/railsjedi)
|
309
|
+
- [Fred Wu](http://github.com/fredwu)
|
310
|
+
* [Piotr Kuczynski](http://github.com/pkuczynski)
|
311
|
+
- Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
|
312
|
+
|
313
|
+
## License
|
314
|
+
|
315
|
+
Config is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|