palkan/anyway_config

Default config_name of classes with multiple words ought be underscore-separated

dhnaranjo opened this issue · 5 comments

What did you do?

  1. Made a config called GoodJobConfig
  2. required some attributes in that config
  3. Provided a default in config/good_job.yml

What did you expect to happen?

App starts, defaults loaded

What actually happened?

AnywayConfig looks for configurations for goodjob, fails to load the yml file contents, spits out the following error.

Uncaught exception: The following config parameters for `GoodJobConfig(config_name: goodjob)` are missing or empty: max_threads, execution_mode, enable_cron
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:455:in `raise_validation_error'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:442:in `block in validate_required_attributes!'
	<internal:kernel>:124:in `then'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:440:in `validate_required_attributes!'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:78:in `apply_to'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:377:in `block in load'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:377:in `each'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:377:in `load'
	/Users/dazmin/.gem/ruby/3.1.2/gems/anyway_config-2.3.0/lib/anyway/config.rb:337:in `initialize'
	/Users/dazmin/mmx/config/configs/application_config.rb:14:in `new'
	/Users/dazmin/mmx/config/configs/application_config.rb:14:in `instance'
	/Users/dazmin/.gem/ruby/3.1.2/gems/activesupport-7.0.3.1/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
	/Users/dazmin/mmx/config/application.rb:39:in `<class:Application>'
	/Users/dazmin/mmx/config/application.rb:11:in `<module:Mmx>'
	/Users/dazmin/mmx/config/application.rb:9:in `<top (required)>'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/commands/server/server_command.rb:137:in `require'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/commands/server/server_command.rb:137:in `block in perform'
	<internal:kernel>:90:in `tap'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/commands/server/server_command.rb:134:in `perform'
	/Users/dazmin/.gem/ruby/3.1.2/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	/Users/dazmin/.gem/ruby/3.1.2/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	/Users/dazmin/.gem/ruby/3.1.2/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/command/base.rb:87:in `perform'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/command.rb:48:in `invoke'
	/Users/dazmin/.gem/ruby/3.1.2/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<top (required)>'
	/Users/dazmin/mmx/bin/rails:4:in `require'
	/Users/dazmin/mmx/bin/rails:4:in `<top (required)>'
	/Users/dazmin/.gem/ruby/3.1.2/gems/debase-3.0.0.beta.4/lib/debase.rb:211:in `load_protect'
	/Users/dazmin/.gem/ruby/3.1.2/gems/debase-3.0.0.beta.4/lib/debase.rb:211:in `debug_load'

Process finished with exit code 1

Additional context

I was able to work around this error by setting config_name :good_job.

Environment

Ruby Version:
3.1.2

Framework Version (Rails, whatever):
Rails 7.0.3.1

Anyway Config Version:
2.3.0

I recognize that this is pretty much an opinion, and that this would be a breaking change, so if you're like "Nah no thanks" I get it. If you are into it I'd be happy to put a PR together.

It's not really an opinion but a legacy (which I forgot to fix in the 2.0 release).

You're right, this is a breaking change (a potentially huge one), so we can not just change the behavior right now.

Word. Well, there's a perfectly serviceable workaround in config_name, so no stress.

Eeeek - first time using the gem and ran straight into this!

At least I understand why things aren't working for me now - will go with the config_name workaround for now

This was with generated code however, e.g.

rails generate anyway:config api_service scheme host password

Should the generator have automatically added the config_name: api_service setting to the generated config class? Or named the YML file as apiservice.yml instead of api_service.yml instead?

palkan commented

Should the generator have automatically added the config_name: api_service setting to the generated config class?

Yeah, that's a good suggestion. Added. Will be released in 2.5.0.