Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1483002
Created the new config for using a different envfironment, instead of…
neilwilliamsdvla Nov 3, 2020
544832b
Reverting work on additional feature and addressing PR comments
neilwilliamsdvla Nov 25, 2020
905d18f
Merge branch 'master' of https://github.com/rubyconfig/config into fe…
neilwilliamsdvla Nov 25, 2020
ca21f0e
Removing unnecessary whitespace
neilwilliamsdvla Nov 25, 2020
a1c01df
Bumping version number
neilwilliamsdvla Nov 25, 2020
536dbfa
Merge branch 'master' into feature/rails-alternative-environment
pkuczynski Nov 25, 2020
e529403
Update config.gemspec
pkuczynski Nov 25, 2020
f769e1e
Update options.rb
pkuczynski Nov 25, 2020
6ecf263
Update version.rb
pkuczynski Nov 25, 2020
b315448
Updating CHANGELOG, updating README and reverting version back to wha…
neilwilliamsdvla Dec 2, 2020
1708e42
Reverting version back to what it was
neilwilliamsdvla Dec 2, 2020
8f1c31d
Merge branch 'master' of https://github.com/rubyconfig/config into fe…
neilwilliamsdvla Dec 2, 2020
4e60380
Merge branch 'feature/rails-alternative-environment' of github.com:ne…
neilwilliamsdvla Dec 2, 2020
65f4d60
Merge branch 'master' into feature/rails-alternative-environment
pkuczynski Dec 8, 2020
26df03b
Update CHANGELOG.md
pkuczynski Dec 8, 2020
ee039b2
Update CHANGELOG.md
pkuczynski Dec 8, 2020
342d7cb
Update CHANGELOG.md
pkuczynski Dec 8, 2020
8627c67
Update README.md
pkuczynski Dec 8, 2020
c772319
Update README.md
pkuczynski Dec 8, 2020
ee71de1
Update config.rb
pkuczynski Dec 8, 2020
166b25c
Merge branch 'master' into feature/rails-alternative-environment
pkuczynski Dec 8, 2020
8df31ba
Fixing condition on gem platform in the gemspec to make more sense
neilwilliamsdvla Jan 13, 2021
3e775aa
Init commit and adding 6.1 rails
Apr 13, 2021
c3e732e
Adding rails 6.1
Apr 13, 2021
73711af
fixture files added for non rails envs
Apr 15, 2021
a0eedc5
Merge branch 'feature/rails-alternative-environment' of https://githu…
Apr 15, 2021
5935248
any_env.yml - Added these to show that other environment files can be…
Apr 20, 2021
5310f02
config.rb - An initialiser added to override the default behaviour fr…
Apr 20, 2021
a1dff18
config_env_spec.rb - Removed previous code that was added incorrectly
Apr 20, 2021
561c582
preprod.yml - Removed due to using a more obvious naming as people mi…
Apr 20, 2021
214a5c1
rails_**.gemfile - Adeded byebug for testing
Apr 20, 2021
5c67eee
spec_helper.rb - Added the env var to set the environment file name o…
Apr 20, 2021
f696df8
stage.yml - Renamed to be more explicit
Apr 20, 2021
a8b7f8c
Missed tests and config
Apr 20, 2021
a4cb1d4
Initialising the config object as a different name from the rails app…
neilwilliamsdvla Apr 21, 2021
a8e2564
Tweaking the config of the new rails apps and pushing the intermitten…
neilwilliamsdvla Jul 12, 2021
1361114
Merging master and fixing conflicts
neilwilliamsdvla Jul 12, 2021
8415576
Merging unit test branch into rails-alternative-environment and fixin…
neilwilliamsdvla Jul 12, 2021
ec3f2b9
Fixing syntax error after merge conflicts
neilwilliamsdvla Jul 12, 2021
997e1c4
Removing byebug history and ignoring from git
neilwilliamsdvla Jul 12, 2021
1b9b8e0
ignoring errors requiring byebug in the CI environment - useful for l…
neilwilliamsdvla Jul 12, 2021
12b112f
Don't require byebug when in CI environment
neilwilliamsdvla Jul 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tmp
.sass-cache
Gemfile.lock
*.gem
.byebug_history
18 changes: 16 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
appraise 'rails-5.2' do
gem 'activerecord-jdbcsqlite3-adapter', '~> 52.5', platform: :jruby
gem 'bootsnap', '~> 1.4'
gem 'rails', '5.2.4.3'
gem 'rails', '5.2.5'
gem 'rspec-rails', '~> 3.7'
gem 'sqlite3', '< 1.4.0', platform: :ruby
end
Expand All @@ -41,14 +41,28 @@ if (RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0') || RUBY_ENGINE != 'ruby'
appraise 'rails-6.0' do
gem 'activerecord-jdbcsqlite3-adapter', '~> 60.1', platform: :jruby
gem 'bootsnap', '~> 1.4'
gem 'rails', '6.0.3.1'
gem 'rails', '6.0.3.6'
gem 'rspec-rails', '~> 3.7'
gem 'sqlite3', '~> 1.4.0', platform: :ruby
end
else
puts 'Skipping rails-6.0 for Ruby < 2.5'
end

# Rails 6.x requires Ruby >= 2.5.0
if (RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0') || RUBY_ENGINE != 'ruby'
appraise 'rails-6.1' do
gem 'activerecord-jdbcsqlite3-adapter', '~> 60.1', platform: :jruby
gem 'bootsnap', '~> 1.4'
gem 'rails', '6.1.3.1'
gem 'rspec-rails', '~> 3.7'
gem 'sqlite3', '~> 1.4.0', platform: :ruby
end
else
puts 'Skipping rails-6.0 for Ruby < 2.5'
end


appraise 'sinatra' do
gem 'sinatra', '2.0.8.1'
end
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

### Changes

* Add option to specify environment (default: `RAILS_ENV`) ([#290](https://github.com/rubyconfig/config/pull/290))
* Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228))
* Add exit! to reserved keywords ([#289](https://github.com/railsconfig/config/issues/289))

Expand Down
71 changes: 37 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ Config helps you easily manage environment specific settings in an easy and usab

## Features

* simple YAML config files
* config files support ERB
* config files support inheritance and multiple environments
* access config information via convenient object member notation
* support for multi-level settings (`Settings.group.subgroup.setting`)
* local developer settings ignored when committing the code
- simple YAML config files
- config files support ERB
- config files support inheritance and multiple environments
- access config information via convenient object member notation
- support for multi-level settings (`Settings.group.subgroup.setting`)
- local developer settings ignored when committing the code

## Compatibility

Current version supports and is [tested](.github/workflows/tests.yml#L19) for the following interpreters and frameworks:

* Interpreters
* [Ruby](https://www.ruby-lang.org) `>= 2.4`
* [JRuby](https://www.jruby.org) `>= 9.2`
* [TruffleRuby](https://github.com/oracle/truffleruby) `>= 19.3`
* Application frameworks
* Rails `>= 4.2`, `5` and `6`
* Padrino
* Sinatra
- Interpreters
- [Ruby](https://www.ruby-lang.org) `>= 2.4`
- [JRuby](https://www.jruby.org) `>= 9.2`
- [TruffleRuby](https://github.com/oracle/truffleruby) `>= 19.3`
- Application frameworks
- Rails `>= 4.2`, `5` and `6`
- Padrino
- Sinatra

For Ruby `2.0` to `2.3` or Rails `3` to `4.1` use version `1.x` of this gem. For older versions of Rails or Ruby use [AppConfig](http://github.com/fredwu/app_config).

Expand All @@ -52,6 +52,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 Expand Up @@ -209,21 +211,21 @@ Embedded Ruby is allowed in the YAML configuration files. ERB will be evaluated

Consider the two following config files.

* ```#{Rails.root}/config/settings.yml```
- `#{Rails.root}/config/settings.yml`

```yaml
size: 1
server: google.com
```

* ```#{Rails.root}/config/environments/development.yml```
- `#{Rails.root}/config/environments/development.yml`

```yaml
size: 2
computed: <%= 1 + 2 + 3 %>
section:
size: 3
servers: [ {name: yahoo.com}, {name: amazon.com} ]
servers: [{ name: yahoo.com }, { name: amazon.com }]
```

Notice that the environment specific config entries overwrite the common entries.
Expand Down Expand Up @@ -267,15 +269,16 @@ After installing `Config` in Rails, you will find automatically generated file t

### General

* `const_name` - name of the object holing you settings. Default: `'Settings'`
* `evaluate_erb_in_yaml` - evaluate ERB in YAML config files. Set to false if the config file contains ERB that should not be evaluated at load time. Default: `true`
- `const_name` - name of the object holding you settings. Default: `'Settings'`
- `environment` - define current environment, affecting which settings file will be loaded. Default: `Rails.env`
- `evaluate_erb_in_yaml` - evaluate ERB in YAML config files. Set to false if the config file contains ERB that should not be evaluated at load time. Default: `true`

### Merge customization

* `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true`
* `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false`
* `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil`
* `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.
- `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true`
- `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false`
- `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil`
- `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.

```ruby
# merge_nil_values is true by default
Expand Down Expand Up @@ -448,12 +451,12 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her

You can customize how environment variables are processed:

* `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)
* `env_separator` (default: `'.'`) - what string to use as level separator - default value of `.` works well with Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using dots in variable names might not be allowed (eg. Bash)
* `env_converter` (default: `:downcase`) - how to process variables names:
* `nil` - no change
* `:downcase` - convert to lower case
* `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`)
- `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)
- `env_separator` (default: `'.'`) - what string to use as level separator - default value of `.` works well with Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using dots in variable names might not be allowed (eg. Bash)
- `env_converter` (default: `:downcase`) - how to process variables names:
- `nil` - no change
- `:downcase` - convert to lower case
- `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`)

For instance, given the following environment:

Expand Down Expand Up @@ -492,7 +495,7 @@ For example, the plaintext secret might look like this:
```json
{
"Settings.foo": "hello",
"Settings.bar": "world",
"Settings.bar": "world"
}
```

Expand Down Expand Up @@ -535,10 +538,10 @@ Any and all contributions offered in any form, past present or future are unders

## Authors

* [Piotr Kuczynski](http://github.com/pkuczynski)
* [Fred Wu](http://github.com/fredwu)
* [Jacques Crocker](http://github.com/railsjedi)
* Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
- [Piotr Kuczynski](http://github.com/pkuczynski)
- [Fred Wu](http://github.com/fredwu)
- [Jacques Crocker](http://github.com/railsjedi)
- Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)

## Contributors

Expand Down
10 changes: 7 additions & 3 deletions config.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"

# Default RSpec run will test against latest Rails app
unless ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS']
gems_to_install = /gem "(.*?)", "(.*?)"(?!, platform: (?!\[:ruby\]))/
File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version|
s.add_development_dependency name, version
gems_to_install = /gem "(.*?)", "(.*?)"(?:, platform: \:(.*))?/

File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, platform|
if platform.nil? || platform.to_s == RUBY_ENGINE
s.add_development_dependency name, version
end
end
end

Expand All @@ -50,5 +53,6 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
# Static code analysis to be used locally
s.add_development_dependency 'mdl', '~> 0.9', '>= 0.9.0'
s.add_development_dependency 'rubocop', '~> 0.85.0'
s.add_development_dependency 'byebug', '~> 11.1.3'
end
end
2 changes: 1 addition & 1 deletion gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

gem "activerecord-jdbcsqlite3-adapter", "~> 52.5", platform: :jruby
gem "bootsnap", "~> 1.4"
gem "rails", "5.2.4.3"
gem "rails", "5.2.5"
gem "rspec-rails", "~> 3.7"
gem "sqlite3", "< 1.4.0", platform: :ruby

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "https://rubygems.org"

gem "activerecord-jdbcsqlite3-adapter", "~> 60.1", platform: :jruby
gem "bootsnap", "~> 1.4"
gem "rails", "6.0.3.1"
gem "rails", "6.0.3.6"
gem "rspec-rails", "~> 3.7"
gem "sqlite3", "~> 1.4.0", platform: :ruby

Expand Down
11 changes: 11 additions & 0 deletions gemfiles/rails_6.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord-jdbcsqlite3-adapter", "~> 60.1", platform: :jruby
gem "bootsnap", "~> 1.4"
gem "rails", "6.1.3.1"
gem "rspec-rails", "~> 3.7"
gem "sqlite3", "~> 1.4.0", platform: :ruby

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Config
overwrite_arrays: true,
merge_hash_arrays: false,
validation_contract: nil,
environment: nil,
evaluate_erb_in_yaml: true
)

Expand All @@ -44,7 +45,6 @@ def self.load_files(*files)
end

config.add_source!(Sources::EnvSource.new(ENV)) if Config.use_env

config.load!
config
end
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
4 changes: 4 additions & 0 deletions lib/generators/config/templates/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#
# 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
6 changes: 3 additions & 3 deletions spec/app/rails_4.2/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ default: &default

development:
<<: *default
database: <%= Settings.databases.development.database %>
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= Settings.databases.test.database %>
database: db/test.sqlite3

production:
<<: *default
database: <%= Settings.databases.production.database %>
database: db/production.sqlite3
8 changes: 8 additions & 0 deletions spec/app/rails_4.2/config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is how you would initialize the config object
# when not using the default rails environments

Config.setup do |config|
config.environment = 'any_env'
config.const_name = 'RailtieSettings'
config.env_parse_values = true
end
8 changes: 8 additions & 0 deletions spec/app/rails_4.2/config/settings/any_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# An environment file that doesn't follow
# the default rails environments
#
some_api:
scheme: https
host: some-non-rails-environment
path: /some-path
8 changes: 8 additions & 0 deletions spec/app/rails_5.0/config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is how you would initialize the config object
# when not using the default rails environments

Config.setup do |config|
config.environment = 'any_env'
config.const_name = 'RailtieSettings'
config.env_parse_values = true
end
8 changes: 8 additions & 0 deletions spec/app/rails_5.0/config/settings/any_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# An environment file that doesn't follow
# the default rails environments
#
some_api:
scheme: https
host: some-non-rails-environment
path: /some-path
8 changes: 8 additions & 0 deletions spec/app/rails_5.1/config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is how you would initialize the config object
# when not using the default rails environments

Config.setup do |config|
config.environment = 'any_env'
config.const_name = 'RailtieSettings'
config.env_parse_values = true
end
8 changes: 8 additions & 0 deletions spec/app/rails_5.1/config/settings/any_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# An environment file that doesn't follow
# the default rails environments
#
some_api:
scheme: https
host: some-non-rails-environment
path: /some-path
8 changes: 8 additions & 0 deletions spec/app/rails_5.2/config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is how you would initialize the config object
# when not using the default rails environments

Config.setup do |config|
config.environment = 'any_env'
config.const_name = 'RailtieSettings'
config.env_parse_values = true
end
8 changes: 8 additions & 0 deletions spec/app/rails_5.2/config/settings/any_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# An environment file that doesn't follow
# the default rails environments
#
some_api:
scheme: https
host: some-non-rails-environment
path: /some-path
9 changes: 9 additions & 0 deletions spec/app/rails_6.0/config/initializers/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is how you would initialize the config object
# when not using the default rails environments

Config.setup do |config|
config.environment = 'any_env'
config.const_name = 'RailtieSettings'
config.env_parse_values = true
end

8 changes: 8 additions & 0 deletions spec/app/rails_6.0/config/settings/any_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# An environment file that doesn't follow
# the default rails environments
#
some_api:
scheme: https
host: some-non-rails-environment
path: /some-path
Loading