Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Automatically finds, loads and reloads classes

branch: master

tmp

latest commit 8ab23758e3
Alexey Petrushin authored December 01, 2011
Octocat-spinner-32 lib tmp December 01, 2011
Octocat-spinner-32 spec tmp December 01, 2011
Octocat-spinner-32 .gitignore upd rake October 11, 2010
Octocat-spinner-32 Rakefile minor upd October 30, 2011
Octocat-spinner-32 readme.md add after callback October 30, 2011
readme.md

Automatically finds, loads and reloads classes

Suppose there's following directory structure:

/lib
  /some_class.rb        # class SomeClass; end
  /some_namespace
    /another_class.rb   # class SomeNamespace:AnotherClass; end
  /some_namespace.rb    # module SomeNamespace; end

All these classes will be loaded automatically:

require 'class_loader'

SomeClass
SomeNamespace::AnotherClass

No need for require, autoload and code like this:

require 'some_class'
require 'some_namespace'
require 'some_namespace/another_class'

autoload :SomeClass,      'some_class'
autoload :SomeNamespace,  'some_namespace'
module SomeNamespace
  autoload :AnotherClass, 'some_namespace/another_class'
end

Watching and reloading changed classes:

ClassLoader.watch 'my_app/lib'

Preload classes eagerly:

ClassLoader.preload 'my_app/lib'

Execute callbacks after loading class:

ClassLoader.after 'SomeClass' do |klass|
  klass.include SomeModule
end

It's also very small, sources are about 150 lines (and third of it are comments).

Installation

$ gem install class_loader

License

Copyright (c) Alexey Petrushin http://petrush.in, released under the MIT license.

Something went wrong with that request. Please try again.