Skip to content

Commit 59fffa6

Browse files
neilwilliamsneilwilliamsdvlacjlarose
authored
Configuring the environment name in Rails (#356)
* Bumping rails versions to fix build issues locally * Added a new config option called 'environment', which allows you to overide the default config environment which is the Rails.env. This allows us to have multiple different environments, without having to worry about making custom rails environments --------- Co-authored-by: Neil Williams <[email protected]> Co-authored-by: Chris LaRose <[email protected]>
1 parent 9c23cbb commit 59fffa6

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ which will generate customizable config file `config/initializers/config.rb` and
5353

5454
You can now edit them to adjust to your needs.
5555

56+
> Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`.
57+
5658
### Installing on Padrino
5759

5860
Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`

lib/config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module Config
2727
overwrite_arrays: true,
2828
merge_hash_arrays: false,
2929
validation_contract: nil,
30-
evaluate_erb_in_yaml: true
30+
evaluate_erb_in_yaml: true,
31+
environment: nil
3132
)
3233

3334
def self.setup

lib/config/integrations/rails/railtie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def preload
99

1010
# Parse the settings before any of the initializers
1111
Config.load_and_set_settings(
12-
Config.setting_files(::Rails.root.join('config'), ::Rails.env)
12+
Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
1313
)
1414
end
1515

lib/generators/config/templates/config.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#
1616
# config.overwrite_arrays = true
1717

18+
# Defines current environment, affecting which settings file will be loaded.
19+
# Default: `Rails.env`
20+
#
21+
# config.environment = ENV.fetch('ENVIRONMENT', :development)
22+
1823
# Load environment variables from the `ENV` object and override any settings defined in files.
1924
#
2025
# config.use_env = false

0 commit comments

Comments
 (0)