GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Ruby library for auto-loading and auto-creation of classes and modules.
Homepage: http://dev.zeraweb.com/autocode
Clone URL: git://github.com/dyoder/autocode.git
name age message
file HISTORY Sun May 18 22:55:11 -0700 2008 Updated HISTORY, README, and added 'publish' ta... [dyoder]
file README Sun May 18 22:55:11 -0700 2008 Updated HISTORY, README, and added 'publish' ta... [dyoder]
file Rakefile Mon Jun 09 08:21:02 -0700 2008 Added additional authors. [dyoder]
file autocode.gemspec Thu May 15 18:35:48 -0700 2008 gemspec update [automatthew]
directory lib/ Fri Aug 08 17:34:01 -0700 2008 Some slight tuning and now AutoCode will fail i... [dyoder]
directory test/ Sun Jun 08 13:39:50 -0700 2008 Added the begnnings for tests of normalization ... [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.