palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Unable to exclude environments in Rails configuration file #79

Closed jtuttle closed 3 years ago

jtuttle commented 3 years ago

What did you do?

The README says you can't mix-and-match environment and non-environment values in the config file but it seems like I should be able to have one or the other.

In a Rails app, I tried to use a YAML configuration file without specifying any environments:

my_config.rb

class MyConfig < Anyway::Config
  attr_config :foo
end

my.yml

foo: bar

What did you expect to happen?

I expected MyConfig to read the value of foo as "bar".

What actually happened?

The MyConfig object is unable to read the value of foo from the YAML file:

[1] pry(main)> require_relative './lib/config/my_config.rb'
=> true
[2] pry(main)> MyConfig.new.foo
=> nil

Additional context

I'm able to load the value just fine if I include the Rails env in the config file, so I know it's not a mistake setting up paths or anything like that. If I change the config file as follows it works:

my.yml

development:
  foo: bar
[1] pry(main)> require_relative './lib/conjur/my_config.rb'
=> true
[2] pry(main)> MyConfig.new.foo
=> "bar"

but for this particular use case I don't want to have to specify environments in the config file.

Environment

Ruby Version: Ruby 2.5.8p224

Framework Version (Rails, whatever): Rails 5.2.6

Anyway Config Version: 2.1.0

jtuttle commented 3 years ago

Fortunately, I was able to fix this by setting config.anyway_config.future.unwrap_known_environments = true in config/application.rb. However, the README makes it sound like this setting is just supposed to allow you to mix-and-match env with non-env rather than enabling files that are completely non-env so I think there may still be a bug here. Going to leave this open for now.

palkan commented 3 years ago

Thanks! Updated the Readme verbiage a bit.