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.
Files changed (199) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +6 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +2 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +23 -0
  8. data/Appraisals +15 -0
  9. data/CHANGELOG.md +25 -0
  10. data/Gemfile +6 -0
  11. data/LICENSE.md +27 -0
  12. data/README.md +315 -0
  13. data/Rakefile +42 -0
  14. data/config.gemspec +46 -0
  15. data/gemfiles/rails_3.gemfile +7 -0
  16. data/gemfiles/rails_4.1.gemfile +7 -0
  17. data/gemfiles/rails_4.2.gemfile +7 -0
  18. data/gemfiles/rails_4.gemfile +7 -0
  19. data/lib/config.rb +64 -0
  20. data/lib/config/engine.rb +5 -0
  21. data/lib/config/integration/rails.rb +36 -0
  22. data/lib/config/integration/sinatra.rb +26 -0
  23. data/lib/config/options.rb +157 -0
  24. data/lib/config/rack/reloader.rb +15 -0
  25. data/lib/config/railtie.rb +9 -0
  26. data/lib/config/sources/yaml_source.rb +26 -0
  27. data/lib/config/tasks.rb +59 -0
  28. data/lib/config/tasks/heroku.rake +8 -0
  29. data/lib/config/version.rb +3 -0
  30. data/lib/generators/config/install_generator.rb +32 -0
  31. data/lib/generators/config/templates/rails_config.rb +3 -0
  32. data/lib/generators/config/templates/settings.local.yml +0 -0
  33. data/lib/generators/config/templates/settings.yml +0 -0
  34. data/lib/generators/config/templates/settings/development.yml +0 -0
  35. data/lib/generators/config/templates/settings/production.yml +0 -0
  36. data/lib/generators/config/templates/settings/test.yml +0 -0
  37. data/spec/app/rails_3/Rakefile +7 -0
  38. data/spec/app/rails_3/app/assets/javascripts/application.js +13 -0
  39. data/spec/app/rails_3/app/assets/stylesheets/application.css +13 -0
  40. data/spec/app/rails_3/app/controllers/application_controller.rb +3 -0
  41. data/spec/app/rails_3/app/helpers/application_helper.rb +2 -0
  42. data/spec/app/rails_3/app/models/.gitkeep +0 -0
  43. data/spec/app/rails_3/app/views/layouts/application.html.erb +14 -0
  44. data/spec/app/rails_3/bin/bundle +3 -0
  45. data/spec/app/rails_3/bin/rails +4 -0
  46. data/spec/app/rails_3/bin/rake +4 -0
  47. data/spec/app/rails_3/config.ru +4 -0
  48. data/spec/app/rails_3/config/application.rb +29 -0
  49. data/spec/app/rails_3/config/boot.rb +5 -0
  50. data/spec/app/rails_3/config/database.yml +25 -0
  51. data/spec/app/rails_3/config/environment.rb +5 -0
  52. data/spec/app/rails_3/config/environments/development.rb +42 -0
  53. data/spec/app/rails_3/config/environments/production.rb +72 -0
  54. data/spec/app/rails_3/config/environments/test.rb +42 -0
  55. data/spec/app/rails_3/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/app/rails_3/config/initializers/inflections.rb +15 -0
  57. data/spec/app/rails_3/config/initializers/mime_types.rb +5 -0
  58. data/spec/app/rails_3/config/initializers/secret_token.rb +7 -0
  59. data/spec/app/rails_3/config/initializers/session_store.rb +8 -0
  60. data/spec/app/rails_3/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/app/rails_3/config/locales/en.yml +5 -0
  62. data/spec/app/rails_3/config/routes.rb +2 -0
  63. data/spec/app/rails_3/config/settings.yml +7 -0
  64. data/spec/app/rails_3/db/.gitkeep +0 -0
  65. data/spec/app/rails_3/public/404.html +26 -0
  66. data/spec/app/rails_3/public/422.html +26 -0
  67. data/spec/app/rails_3/public/500.html +25 -0
  68. data/spec/app/rails_3/script/rails +6 -0
  69. data/spec/app/rails_4.1/Rakefile +6 -0
  70. data/spec/app/rails_4.1/app/assets/javascripts/application.js +13 -0
  71. data/spec/app/rails_4.1/app/assets/stylesheets/application.css +15 -0
  72. data/spec/app/rails_4.1/app/controllers/application_controller.rb +5 -0
  73. data/spec/app/rails_4.1/app/helpers/application_helper.rb +2 -0
  74. data/spec/app/rails_4.1/app/models/.keep +0 -0
  75. data/spec/app/rails_4.1/app/views/layouts/application.html.erb +14 -0
  76. data/spec/app/rails_4.1/bin/bundle +3 -0
  77. data/spec/app/rails_4.1/bin/rails +4 -0
  78. data/spec/app/rails_4.1/bin/rake +4 -0
  79. data/spec/app/rails_4.1/config.ru +4 -0
  80. data/spec/app/rails_4.1/config/application.rb +27 -0
  81. data/spec/app/rails_4.1/config/boot.rb +5 -0
  82. data/spec/app/rails_4.1/config/database.yml +25 -0
  83. data/spec/app/rails_4.1/config/environment.rb +5 -0
  84. data/spec/app/rails_4.1/config/environments/development.rb +42 -0
  85. data/spec/app/rails_4.1/config/environments/production.rb +88 -0
  86. data/spec/app/rails_4.1/config/environments/test.rb +44 -0
  87. data/spec/app/rails_4.1/config/initializers/backtrace_silencers.rb +7 -0
  88. data/spec/app/rails_4.1/config/initializers/cookies_serializer.rb +3 -0
  89. data/spec/app/rails_4.1/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/spec/app/rails_4.1/config/initializers/inflections.rb +16 -0
  91. data/spec/app/rails_4.1/config/initializers/mime_types.rb +4 -0
  92. data/spec/app/rails_4.1/config/initializers/session_store.rb +3 -0
  93. data/spec/app/rails_4.1/config/initializers/wrap_parameters.rb +14 -0
  94. data/spec/app/rails_4.1/config/locales/en.yml +23 -0
  95. data/spec/app/rails_4.1/config/routes.rb +2 -0
  96. data/spec/app/rails_4.1/config/secrets.yml +22 -0
  97. data/spec/app/rails_4.1/config/settings.yml +7 -0
  98. data/spec/app/rails_4.1/db/.keep +0 -0
  99. data/spec/app/rails_4.1/public/404.html +67 -0
  100. data/spec/app/rails_4.1/public/422.html +67 -0
  101. data/spec/app/rails_4.1/public/500.html +66 -0
  102. data/spec/app/rails_4.2/Rakefile +6 -0
  103. data/spec/app/rails_4.2/app/assets/images/.keep +0 -0
  104. data/spec/app/rails_4.2/app/assets/javascripts/application.js +16 -0
  105. data/spec/app/rails_4.2/app/assets/stylesheets/application.css +15 -0
  106. data/spec/app/rails_4.2/app/controllers/application_controller.rb +5 -0
  107. data/spec/app/rails_4.2/app/controllers/concerns/.keep +0 -0
  108. data/spec/app/rails_4.2/app/helpers/application_helper.rb +2 -0
  109. data/spec/app/rails_4.2/app/mailers/.keep +0 -0
  110. data/spec/app/rails_4.2/app/models/.keep +0 -0
  111. data/spec/app/rails_4.2/app/models/concerns/.keep +0 -0
  112. data/spec/app/rails_4.2/app/views/layouts/application.html.erb +14 -0
  113. data/spec/app/rails_4.2/bin/bundle +3 -0
  114. data/spec/app/rails_4.2/bin/rails +8 -0
  115. data/spec/app/rails_4.2/bin/rake +8 -0
  116. data/spec/app/rails_4.2/bin/setup +29 -0
  117. data/spec/app/rails_4.2/bin/spring +15 -0
  118. data/spec/app/rails_4.2/config.ru +4 -0
  119. data/spec/app/rails_4.2/config/application.rb +31 -0
  120. data/spec/app/rails_4.2/config/boot.rb +3 -0
  121. data/spec/app/rails_4.2/config/database.yml +25 -0
  122. data/spec/app/rails_4.2/config/environment.rb +5 -0
  123. data/spec/app/rails_4.2/config/environments/development.rb +41 -0
  124. data/spec/app/rails_4.2/config/environments/production.rb +79 -0
  125. data/spec/app/rails_4.2/config/environments/test.rb +42 -0
  126. data/spec/app/rails_4.2/config/initializers/assets.rb +11 -0
  127. data/spec/app/rails_4.2/config/initializers/backtrace_silencers.rb +7 -0
  128. data/spec/app/rails_4.2/config/initializers/cookies_serializer.rb +3 -0
  129. data/spec/app/rails_4.2/config/initializers/filter_parameter_logging.rb +4 -0
  130. data/spec/app/rails_4.2/config/initializers/inflections.rb +16 -0
  131. data/spec/app/rails_4.2/config/initializers/mime_types.rb +4 -0
  132. data/spec/app/rails_4.2/config/initializers/session_store.rb +3 -0
  133. data/spec/app/rails_4.2/config/initializers/wrap_parameters.rb +14 -0
  134. data/spec/app/rails_4.2/config/locales/en.yml +23 -0
  135. data/spec/app/rails_4.2/config/routes.rb +56 -0
  136. data/spec/app/rails_4.2/config/secrets.yml +22 -0
  137. data/spec/app/rails_4.2/config/settings.yml +7 -0
  138. data/spec/app/rails_4.2/db/seeds.rb +7 -0
  139. data/spec/app/rails_4.2/public/404.html +67 -0
  140. data/spec/app/rails_4.2/public/422.html +67 -0
  141. data/spec/app/rails_4.2/public/500.html +66 -0
  142. data/spec/app/rails_4.2/public/favicon.ico +0 -0
  143. data/spec/app/rails_4.2/public/robots.txt +5 -0
  144. data/spec/app/rails_4/Rakefile +6 -0
  145. data/spec/app/rails_4/app/assets/javascripts/application.js +13 -0
  146. data/spec/app/rails_4/app/assets/stylesheets/application.css +13 -0
  147. data/spec/app/rails_4/app/controllers/application_controller.rb +5 -0
  148. data/spec/app/rails_4/app/helpers/application_helper.rb +2 -0
  149. data/spec/app/rails_4/app/models/.keep +0 -0
  150. data/spec/app/rails_4/app/views/layouts/application.html.erb +14 -0
  151. data/spec/app/rails_4/bin/bundle +3 -0
  152. data/spec/app/rails_4/bin/rails +4 -0
  153. data/spec/app/rails_4/bin/rake +4 -0
  154. data/spec/app/rails_4/config.ru +4 -0
  155. data/spec/app/rails_4/config/application.rb +27 -0
  156. data/spec/app/rails_4/config/boot.rb +5 -0
  157. data/spec/app/rails_4/config/database.yml +25 -0
  158. data/spec/app/rails_4/config/environment.rb +5 -0
  159. data/spec/app/rails_4/config/environments/development.rb +34 -0
  160. data/spec/app/rails_4/config/environments/production.rb +85 -0
  161. data/spec/app/rails_4/config/environments/test.rb +41 -0
  162. data/spec/app/rails_4/config/initializers/backtrace_silencers.rb +7 -0
  163. data/spec/app/rails_4/config/initializers/filter_parameter_logging.rb +4 -0
  164. data/spec/app/rails_4/config/initializers/inflections.rb +16 -0
  165. data/spec/app/rails_4/config/initializers/mime_types.rb +5 -0
  166. data/spec/app/rails_4/config/initializers/secret_token.rb +12 -0
  167. data/spec/app/rails_4/config/initializers/session_store.rb +3 -0
  168. data/spec/app/rails_4/config/initializers/wrap_parameters.rb +14 -0
  169. data/spec/app/rails_4/config/locales/en.yml +23 -0
  170. data/spec/app/rails_4/config/routes.rb +2 -0
  171. data/spec/app/rails_4/config/settings.yml +7 -0
  172. data/spec/app/rails_4/db/.keep +0 -0
  173. data/spec/app/rails_4/public/404.html +58 -0
  174. data/spec/app/rails_4/public/422.html +58 -0
  175. data/spec/app/rails_4/public/500.html +57 -0
  176. data/spec/config_spec.rb +317 -0
  177. data/spec/fixtures/bool_override/config1.yml +2 -0
  178. data/spec/fixtures/bool_override/config2.yml +2 -0
  179. data/spec/fixtures/custom_types/hash.yml +7 -0
  180. data/spec/fixtures/deep_merge/config1.yml +28 -0
  181. data/spec/fixtures/deep_merge/config2.yml +28 -0
  182. data/spec/fixtures/deep_merge2/config1.yml +3 -0
  183. data/spec/fixtures/deep_merge2/config2.yml +2 -0
  184. data/spec/fixtures/development.yml +4 -0
  185. data/spec/fixtures/empty1.yml +0 -0
  186. data/spec/fixtures/empty2.yml +0 -0
  187. data/spec/fixtures/env/settings.yml +4 -0
  188. data/spec/fixtures/malformed.yml +6 -0
  189. data/spec/fixtures/reserved_keywords.yml +2 -0
  190. data/spec/fixtures/settings.yml +21 -0
  191. data/spec/fixtures/settings2.yml +1 -0
  192. data/spec/fixtures/with_erb.yml +4 -0
  193. data/spec/options_spec.rb +84 -0
  194. data/spec/sources/yaml_source_spec.rb +77 -0
  195. data/spec/spec_helper.rb +54 -0
  196. data/spec/support/rails_config_helper.rb +22 -0
  197. data/spec/support/shared_contexts/rake.rb +8 -0
  198. data/spec/tasks/db_spec.rb +9 -0
  199. 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
@@ -0,0 +1,6 @@
1
+ languages:
2
+ Ruby: true
3
+ JavaScript: false
4
+ PHP: false
5
+ # exclude_paths:
6
+ # - "foo/bar.rb"
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ .idea
4
+ .bundle
5
+ gemfiles/*.lock
6
+ log
7
+ pkg
8
+ spec/app/**/db/*.sqlite*
9
+ spec/app/**/log/
10
+ spec/app/**/tmp/
11
+ spec/app/**/.sass-cache
12
+ tmp
13
+ Gemfile.lock
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
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
@@ -0,0 +1,15 @@
1
+ appraise "rails-3" do
2
+ gem "rails", "3.2.22"
3
+ end
4
+
5
+ appraise "rails-4" do
6
+ gem "rails", "4.0.13"
7
+ end
8
+
9
+ appraise "rails-4.1" do
10
+ gem "rails", "4.1.12"
11
+ end
12
+
13
+ appraise "rails-4.2" do
14
+ gem "rails", "4.2.3"
15
+ end
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
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in config.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
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).