Module: Zeroload
- Defined in:
- lib/zeroload.rb,
lib/zeroload/version.rb
Overview
Zeroload Automatically autoload all constants for a module. This requires a change from the current convention of putting class Foo::BarBaz into foo/barbaz.rb (or foo/bar_baz.rb in rails) to using Foo/BarBaz.rb instead.
Constant Summary collapse
- Version =
Gem::Version.new("0.0.1")
Class Method Summary collapse
Class Method Details
.module(mod, directory = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/zeroload.rb', line 9 def self.module(mod, directory=nil) directory ||= caller_locations.first.absolute_path.sub(/\.[^.]*\z/, "".freeze) Dir.glob("#{directory}/*.{rb,so,bundle,dll}") do |path| name = File.basename(path) if /\A[A-Z]/ =~ name name.sub!(/\.[^.]*\z/, "".freeze) warn "#{mod} autoloads #{name} from #{path}" if $VERBOSE mod.autoload :"#{name}", path end end end |