README.md in loader-2.2.1 vs README.md in loader-2.2.2

- old
+ new

@@ -19,10 +19,12 @@ ### Examples load relative directory (not based on Dir.pwd but the caller files position) if you pass multiple string as argument it will be joined by file separator that the OS use +#### Manual loading folders + ```ruby require 'loader' # load all ruby file that was not loaded already @@ -33,75 +35,28 @@ require_relative_directory_r "folder_name/path/etc" ``` -If you like the basic idea that the app should not do any kind of Eager Load and become slow, -you can use the constant based autoload function +#### Autoload folders -simple as this: - -# lib/dog ```ruby - class Dog - def self.say - "Wuff" - end - end + require 'loader' + Loader.autoload ``` -# lib/cat +optionally you can tell the project root folder if you work with in a gem. + ```ruby - class Cat - #some meow here - end + require 'loader' + Loader.autoload(File.dirname(__FILE__)) ``` -# lib/cat/tail -```ruby - class Cat - class Tail +If you like the basic idea that the app should not do any kind of Eager Load and become slow, +you can use the constant based autoload function - def self.grab - "MEOW!!!" - end - - end - end - -``` - -# lib/cat/pawn.rb -```ruby - - class Cat - class Pawn - end - end - -``` - -# lib/bootstrap -```ruby - - require 'loader/autoload' - - # from this point missing constants will be searched by file system path that is based on Object namespace - Loader.autoload - - # no need to load the files , only when they required - Cat::Tail.grab #> "MEOW!!!" - - class Cat - Pawn #> Pawn Constant loaded and returned - end - - class Cat - Dog #> return Top lvl Dog Constant after file is loaded by this Constant request - end - -``` +##### [Sketch about how it works](https://github.com/adamluzsi/loader.rb/blob/master/doc/sketch) \ No newline at end of file