Skip to content

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

Closed
neilwilliams wants to merge 7 commits into
rubyconfig:masterfrom
neilwilliams:feature/rails-alternative-environment
Closed

Rails alternative environment and additional key lookup during env mapping#285
neilwilliams wants to merge 7 commits into
rubyconfig:masterfrom
neilwilliams:feature/rails-alternative-environment

Conversation

@neilwilliams
Copy link
Copy Markdown
Contributor

@neilwilliams neilwilliams commented Nov 6, 2020

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!

Comment thread config.gemspec
if platform.nil?
s.add_development_dependency name, version
else
if platform.to_s == RUBY_ENGINE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but prefer elsif here.

Comment thread config.gemspec
Comment on lines +40 to +41
gems_to_install = /gem "(.*?)", "(.*?)"(, platform: \:(.*))?/
File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, _, platform|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gems_to_install = /gem "(.*?)", "(.*?)"(, platform: \:(.*))?/
File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, _, platform|
gems_to_install = /gem "(.*?)", "(.*?)"(?:, platform: \:(.*))?/
File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(gems_to_install) do |name, version, platform|

I think you can do this to avoid capturing that third unused value

@Fryguy
Copy link
Copy Markdown
Member

Fryguy commented Nov 6, 2020

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.

@neilwilliams neilwilliams deleted the feature/rails-alternative-environment branch November 25, 2020 21:27
@pkuczynski pkuczynski added this to the 2.3.0 milestone Nov 25, 2020
@pkuczynski pkuczynski modified the milestones: 2.3.0, 2.2.2 Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants