I wanted to have the ability to auto-load dependencies based on the symbol name the way Rails does in my own non-Rails project, as it would save me writing a lot of require statements.
This can be achieved using ActiveSupport.
I added a file called boot.rb which is included in the other files of the project.
First of all, the file should require the active_support gem. I use Bundler, so in my case I specified a dependency on activesupport in the Gemfile and then loaded the Bundler environment in boot.rb:
After that, I added the following lines:
Dependencies.load_paths << File.join(File.dirname(__FILE__), 'config')
Dependencies.load_paths << File.join(File.dirname(__FILE__), 'lib')
This code means that unknown symbols will be resolved by searching the files inside the config and lib folders. Also, to force the inclusion of a particular file in case the load can't be triggered by an unknown symbol name, you can do:
After setting up boot.rb, you just need to require it in the files that do actual real work to get automatic dependency loading:
Works using: activesupport 2.3.5