Permalink
Browse files

Use Module#autoload to lazy-load nested source files

  • Loading branch information...
1 parent 87e79c4 commit 8c704dbb03d8dc89c20b7e6bdb781f77222bcbdb @njonsson committed Jan 12, 2015
Showing with 16 additions and 9 deletions.
  1. +10 −4 lib/cape.rb
  2. +6 −5 lib/cape/core_ext.rb
View
@@ -1,10 +1,16 @@
-::Dir.glob(::File.expand_path('../cape/*.rb', __FILE__)) do |f|
- require "cape/#{::File.basename f, '.rb'}"
-end
-
# Contains the implementation of Cape.
module Cape
+ autoload :Capistrano, 'cape/capistrano'
+ autoload :CoreExt, 'cape/core_ext'
+ autoload :DSL, 'cape/dsl'
+ autoload :HashList, 'cape/hash_list'
+ autoload :Rake, 'cape/rake'
+ autoload :RecipeDefinition, 'cape/recipe_definition'
+ autoload :Util, 'cape/util'
+ autoload :VERSION, 'cape/version'
+ autoload :XTerm, 'cape/xterm'
+
extend DSL
end
View
@@ -1,12 +1,13 @@
-::Dir.glob(::File.expand_path('../core_ext/*.rb', __FILE__)) do |f|
- require "cape/core_ext/#{::File.basename f, '.rb'}"
-end
-
module Cape
# Contains extensions to core types.
#
# @api private
- module CoreExt; end
+ module CoreExt
+
+ autoload :Hash, 'cape/core_ext/hash'
+ autoload :Symbol, 'cape/core_ext/symbol'
+
+ end
end

0 comments on commit 8c704db

Please sign in to comment.