Class: OpenSession::RecursivelyRequire
- Inherits:
-
Object
- Object
- OpenSession::RecursivelyRequire
- Defined in:
- lib/session/require.gem.rb
Overview
Require every file with a dot rb extension that is either directly in or recursively below the calling gem’s directory.
Note that this class and its methods depend on an initialized logger so as a pre-condition, ensure the logging has been instantiated before calling.
The Base Require Path
Here is an example of the base require path being derived.
Requiring Parental Classes Before Child Classes
This is a common problem when bringing classes in to join the fray. We must require the Planet class before we require the Neptune class.
<tt>class Neptune < Planet</tt>
The solution lies in the directory structure between parent and child classes and this is illustrated by plugins.
Plugins Folder Structure
In the plugins hierarchy, you’ll notice that the child classes are always below the parents. This strategy works if the inheritors are in the same gem as the inherited.
Class Method Summary collapse
-
.now(gem_filepath) ⇒ Object
Require every file with a dot rb extension that is either in or recursively below the file path given in the parameter.
Class Method Details
.now(gem_filepath) ⇒ Object
Require every file with a dot rb extension that is either in or recursively below the file path given in the parameter.
This method logs every file that is required using the INFO log level.
Requiring Parental Classes Before Child Classes
This is a common problem when bringing classes in to join the fray. We must require the Planet class before we require the Neptune class.
<tt>class Neptune < Planet</tt>
The solution lies in the directory structure between parent and child classes and this is illustrated by plugins.
Plugins Folder Structure
In the plugins hierarchy, you’ll notice that the child classes are always below the parents. This strategy works if the inheritors are in the same gem as the inherited.
This require loop is breadth first not depth first so all the parent (base) classes in plugins will be required before their extension classes in the lower subdirectories.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/session/require.gem.rb', line 86 def self.now gem_filepath require_relative "../usecase/cmd" gem_basepath = File. "..", gem_filepath log.info(x) { "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" } log.info(x) { "@@@@ Require Gems In or Under [#{gem_basepath}]" } log.info(x) { "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" } Dir["#{gem_basepath}/**/*.rb"].each do |gem_path| log.info(x) { "@@@@ => #{gem_path}" } require gem_path end log.info(x) { "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" } end |