rubyconfig / config

Easiest way to add multi-environment yaml settings to Rails, Sinatra, Padrino and other Ruby projects.
Other
2.11k stars 231 forks source link

Rails alternative environment and additional key lookup during env mapping #285

Closed neilwilliams closed 3 years ago

neilwilliams commented 4 years ago

There's three main changes in this PR.

  1. A rails app can now configure where the 'environment' comes from. Previously, it was inferred from Rails.environment. We didn't want to pollute RAILS_ENV with actual environments (e.g. stage, preprod). So this change allows the two things to be separated.

  2. Devs are now able to run bundle exec rspec when using the ruby platform

  3. When overriding keys from the environment, there wasn't a way to do this if the keys used in the settings.yml contained the seperation character being used in the environment variables.

E.g. settings.yml

my_config:
  my_second_level_config:
    my_value: "1"

When using:

config.env_separator = '_'

I was never able to overide these settings with:

ENV['MY_CONFIG_MY_SECOND_LEVEL_CONFIG_MY_VALUE'] = "2"

The change allows this to work as expected, but it will still allow the gem to work as it did before. E.g. If the structure above cannot be found, it will set the value under:

my:
  config:
    my:
      second:
        level:
          config:
            my:
              value: ""

Note The code I've created for the third feature is quite crude at the moment, so would appreciate any feedback you have!

Fryguy commented 4 years ago

I only commented on the Ruby env fix...can you please move that into a separate PR, as that is more likely to be merged sooner, and it's unrelated to this PR.