configurations icon indicating copy to clipboard operation
configurations copied to clipboard

configuration_method bug

Open Exelord opened this issue 7 years ago • 5 comments

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

Exelord avatar Dec 13 '17 14:12 Exelord

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?

beatrichartz avatar Dec 20 '17 09:12 beatrichartz

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.

Exelord avatar Dec 20 '17 12:12 Exelord

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

beatrichartz avatar Dec 20 '17 18:12 beatrichartz

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 avatar Jan 15 '18 13:01 Exelord

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

Exelord avatar Jan 15 '18 13:01 Exelord