I’m writing a Rails gem. Where should I require files from other engine? In my engine’s main file or in each file that uses other gem’s functions?
For example, I use devise only in User model (and in configuration file). Should I require it in app/models/user.rb file only? And what about haml gem that is used for rendering each page?
I saw locomotive and forem engines. First requires all other gems in its engine file. And the second require 'kaminari' in engine file and require 'cancan' in models.
What’s right?
IMHO, if your gem has dependencies, then it should require them in the gem’s main file. All the files are read when the gem is loaded, and once the require has been performed, it won’t be performed again. Requiring dependencies in the main file for the gem puts all of the requires in a central location, making maintenance easier.