Project

autoloader

0.0
No commit activity in last 3 years
No release in over 3 years
Crawl a directory at a time, adding files via Kernel#autoload
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme
A couple of handy features to enhance Kernel#autoload.


Features
========

 * Fire Kernel#autoload at an entire directory
 * Fire it again at a subdirectory, for namespace'd models


Motivation/Examples
===================

I was using Ramaze as a web framework, and discovered that the standard Ramaze way of loading a directory of files is to slurp them all (with 'acquire'). I decided I'd rather use autoload, and not load things I'm not using. But I wasn't really looking forward to this:

autoload :User, 'model/user'
autoload :Clan, 'model/clan'
autoload :Item, 'model/item'

...ad nauseum. So, the first feature is a shallow, directory-based autoload:

AutoLoader << 'model'

Of course, being a pedant, I like to namespace my models. I don't want to slurp the entire directory tree. Instead, you can do this:

class User < MyFavoriteORM::Model
  include AutoLoader
  ...
end

Now, all AutoLoaded paths will be searched for a subdirectory called 'user', and all files within will be autoloaded. Just as if you'd done:

User.autoload :Anonymous, 'model/user/anonymous'
User.autoload :Registered, 'model/user/registered'

Of course, there's no requirement that you have a base class, or anything of the sort. If you just want a namespace, you can always do:

module MyNamespace; include AutoLoader; end

And you're done.


Compatibility
=============

Currently, Merb's extlib and Rails' activesupport are supported. It should be trivial to interface with other libraries.