diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cd44cb..6319f40f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 5.4.0 + +### New features + +* Add configuration option `environment` to override the use of `Rails.env` ([#356](https://github.com/rubyconfig/config/pull/356)) + ## 5.3.0 * Remove `dry-validation` from dependencies ([#333](https://github.com/rubyconfig/config/pull/333)) diff --git a/README.md b/README.md index fcecf3e4..119580fe 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/config.rb b/lib/config.rb index 953e9c67..e98d1e70 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -28,7 +28,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 diff --git a/lib/config/integrations/rails/railtie.rb b/lib/config/integrations/rails/railtie.rb index 460fa5f3..6748c116 100644 --- a/lib/config/integrations/rails/railtie.rb +++ b/lib/config/integrations/rails/railtie.rb @@ -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 diff --git a/lib/config/version.rb b/lib/config/version.rb index f29f179a..a4dcdf24 100644 --- a/lib/config/version.rb +++ b/lib/config/version.rb @@ -1,3 +1,3 @@ module Config - VERSION = '5.3.0'.freeze + VERSION = '5.4.0'.freeze end diff --git a/lib/generators/config/templates/config.rb b/lib/generators/config/templates/config.rb index 6ea74ecc..f6a222d0 100644 --- a/lib/generators/config/templates/config.rb +++ b/lib/generators/config/templates/config.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 244b76b8..ca0739e7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -59,6 +59,13 @@ end end +module FixturePathHelper + def fixture_path + # Call fixture_paths.first in Rails >= 7.1 to avoid deprecation warnings + respond_to?(:fixture_paths) ? fixture_paths.first : super + end +end + ## # Common Rspec configure # @@ -84,6 +91,8 @@ def self.reset end end end + + config.include FixturePathHelper end ##