Skip to content

Commit 2f984cd

Browse files
author
Sidelnikov Stanislav
committed
Added README describing Heroku local config workflow. Refs rubyconfig#56
1 parent 017bd98 commit 2f984cd

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,30 @@ Settings.reload!
180180
> 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`
181181
> for your developer specific settings.
182182
183+
## Working with Heroku
184+
185+
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.
186+
187+
To use rails_config with Heroku just set the `use_env` var to `true` in your `config/initializers/rails_config.rb` file. Eg:
188+
189+
```ruby
190+
RailsConfig.setup do |config|
191+
config.const_name = 'AppSettings'
192+
config.use_env = true
193+
end
194+
```
195+
196+
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:
197+
198+
```ruby
199+
ENV['AppSettings.section.size'] = 1
200+
ENV['AppSettings.section.server'] = 'google.com'
201+
```
202+
203+
It won't work with arrays, though.
204+
205+
To upload your local values to Heroku you could ran `bundle exec rake rails_config:heroku`.
206+
183207
## Embedded Ruby (ERB)
184208

185209
Embedded Ruby is allowed in the configuration files. See examples below.

lib/rails_config/tasks/task.rake

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/tasks.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ def vars
2020
)
2121

2222
out = ''
23-
hash = {RailsConfig.const_name => Kernel.const_get(RailsConfig.const_name).to_hash}
24-
dotted_hash = to_dotted_hash hash
23+
dotted_hash = to_dotted_hash Kernel.const_get(RailsConfig.const_name).to_hash, {}, RailsConfig.const_name
2524
dotted_hash.each {|key, value| out += " #{key}=#{value} "}
2625
out
2726
end
@@ -33,7 +32,6 @@ def environment
3332
def heroku(command)
3433
with_app = app ? " --app #{app}" : ""
3534
`heroku #{command}#{with_app}`
36-
#puts "heroku #{command}#{with_app}"
3735
end
3836

3937
def `(command)

0 commit comments

Comments
 (0)