This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Run the following if you haven't already:
gem sources -a http://gems.github.com
Install the gem(s):
sudo gem install dyoder-autocode
commit 78cc57d9839b9d59f7290493ab51f4b47178382a
tree b6563cde258f8d9b0145844078a0c4ad94722745
parent 231ca262a2d9493b813caf8f765fc4ba116672e8
tree b6563cde258f8d9b0145844078a0c4ad94722745
parent 231ca262a2d9493b813caf8f765fc4ba116672e8
autocode /
| name | age | message | |
|---|---|---|---|
| |
HISTORY | Sun May 18 22:55:11 -0700 2008 | [dyoder] |
| |
README | Sun May 18 22:55:11 -0700 2008 | [dyoder] |
| |
Rakefile | Mon Jun 09 08:21:02 -0700 2008 | [dyoder] |
| |
autocode.gemspec | Thu May 15 18:35:48 -0700 2008 | [automatthew] |
| |
lib/ | Fri Aug 08 17:34:01 -0700 2008 | [dyoder] |
| |
test/ | Sun Jun 08 13:39:50 -0700 2008 | [dyoder] |
README
= Introducing AutoCode
AutoCode is a class (and module) loader from Ruby, complete with initialization hooks and reloading. It works as a mixin
and uses #const_remove for unloading so there can never be any artifacts from prior loads hanging around.
require 'autocode'
module Application
include AutoCode
auto_load true, :directories => [ :configurations, :models, :views, :controllers ]
end
This will attempt to load code dynamically from the given directories, using the module name to determine which
directory to look in. Thus, <tt>Application::CustomerModel</tt> could load the file <tt>models/customer_model.rb</tt>.
== Reloading Code
Auto-loaded or created code is automatically reloadable (very useful when debugging running processes). Just call reload
on any given module.
*Important*: Only code loaded via *AutoCode* (auto_load or auto_create) will be reloaded.
== Autocreation
Sometimes it's useful to generate defaults for classes or modules that don't exist. This can be particularly powerful
when used in combination with auto_loading.
require 'auto_code'
module Application
include AutoCode
%w( Models Views Controllers ).each |name| do
auto_create_module name do
include AutoCode
auto_load true, :directories => [ name.downcase ]
end
end
end
This will auto_create the modules Configurations, Models, Views, and Controllers within the Application module, as they
are referenced, and then initialize them so that they will automatically load source files from the corresponding
directories.
For example, referencing <tt>Application::Models::Customer</tt> will cause the file <tt>models/customer.rb</tt> to be
loaded.
== Initializing
Sometimes you want to reopen a class or module and add or change methods, etc. However, in the case of auto-loading or
creating unless your code is in an auto_load or auto_create block, it will get clobbered upon reload. You address this
using auto_eval which registers blocks against constant names so that auto_create and auto_load can run them after
object creation.
require 'auto_code'
module Application
include AutoCode
Models.auto_eval(true) do
set_model self.name
end
end
== Other Uses
Autoloading and autocreation, along with reloading, can be used to provide sophisticated rules for loading and even
generating modules and classes within a given module. These capabilities are increasingly found within frameworks like
Rails and Camping, but *AutoCode* makes it possible to mixin these capabilities into any situation and precisely control
how they are applied.
== Support
If you have questions or comments, please go to the Waves support forum (which also supports AutoCode, since AutoCode is
principally used within Waves) at http://groups.google.com/group/rubywaves.
(c) 2007 Dan Yoder
Licensed under the MIT License.





