beatrichartz / configurations

Configurations provides a unified approach to do configurations for gems or other ruby code
MIT License
140 stars 9 forks source link

configuration_method bug #18

Open Exelord opened 6 years ago

Exelord commented 6 years ago

Bug description

If you want to define configuration_method and you don't have another key in the scope, eg. :my the method won't be defined.

MyApp.configure do |c|
end
  configuration_method my: :level do
    # do sth
  end
MyApp.my.level # my is not configured
beatrichartz commented 6 years ago

Thanks for raising this. I'm not sure what the usecase is to configure a method on an otherwise unused scope, can you provide an example?

Exelord commented 6 years ago

In the case when you are using scopes just for categorizing things this is pretty useful. Eg, for different scopes you have a diffrent method which calls the same. Right now I have to define an empty default key for the scope if I want to use a method in it.

beatrichartz commented 6 years ago

Sounds interesting - can you provide an example usage in code?

Exelord commented 6 years ago

Sure, eg you can have:

  configuration_method cars: :engine_types do
    Engines.for.cars
  end

  configuration_method bikes: :engine_types do
    Engines.for.bikes
  end

And in that case to have it worked I need to define defaults nil for :cars and :bikes

Exelord commented 6 years ago

Also, Is there any possibility to access different scope in a method? use-case example:

MyApp.configure do |c|
  c.host = 'mydomain.com'
end
  configuration_method emails: :email_for do |name|
    "#{name}@#{host}"
  end

Unfortunately the host doesn't exist in that context