What a difference a version makes! In my Rails 3.2 application, I was using concerns, and they were set up like so:
--app
--models
category.rb
product.rb
--concerns
--category
third_party_a.rb
third_party_b.rb
--product
third_party_a.rb
third_party_b.rb
--warehouse
third_party_a.rb
third_party_b.rb
I have concerns with the same name, namespaced into different directories. It was how I was taught to do it, and it makes a lot better sense than the Rails 4.2 default of lumping a bunch of Ruby files in a concerns directory. If I have multiple objects that need to interact with multiple third party APIs, then this is the very best way.
But upgrading this application to Rails 4.2, well, it refuses to work. I'm getting lots, and lots, and lots of complaints on the concerns:
Unable to autoload constant Category::ThirdPartyA
it "expected the file to define it" or something. The file looks like this:
module EbayInteraction
extend ActiveSupport::Concern
module ClassMethods
...
No, there's no other namespace in there. But Rails 3.2 didn't require it. And it worked flawlessly.
So I go into the file and change the declaration to:
module Category::ThirdPartyA
I have no idea if that is correct. I am very confused by modules and namespaces, and neither concept makes any sense at all to me.
And then I go into the model itself and include the concern like this:
include Category::ThirdPartyA
And I get past the error. Then complains about ThirdPartyB, so I do the same. And so on.
When I'm finished, I now get this complaint:
Circular dependency detected while autoloading constant Category::ThirdPartyA
That is a silly and misleading error. That concern has exactly one slim method. No possibility of anything circular.
Now I am stuck. My only alternative is to rename all of my files and lump them into the concerns directory. I really don't want to do that, it's not maintainable or extensible. What is going on here?