Skip to content

Commit

Permalink
Configuring the environment name in Rails (#356)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Mar 16, 2024
1 parent 9c23cbb commit 59fffa6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ which will generate customizable config file `config/initializers/config.rb` and

You can now edit them to adjust to your needs.

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

Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`
Expand Down
3 changes: 2 additions & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module Config
overwrite_arrays: true,
merge_hash_arrays: false,
validation_contract: nil,
evaluate_erb_in_yaml: true
evaluate_erb_in_yaml: true,
environment: nil
)

def self.setup
Expand Down
2 changes: 1 addition & 1 deletion lib/config/integrations/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def preload

# Parse the settings before any of the initializers
Config.load_and_set_settings(
Config.setting_files(::Rails.root.join('config'), ::Rails.env)
Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
)
end

Expand Down
5 changes: 5 additions & 0 deletions lib/generators/config/templates/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#
# config.overwrite_arrays = true

# Defines current environment, affecting which settings file will be loaded.
# Default: `Rails.env`
#
# config.environment = ENV.fetch('ENVIRONMENT', :development)

# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false
Expand Down

0 comments on commit 59fffa6

Please sign in to comment.