Class: RequireDir::Loader
- Inherits:
-
Object
- Object
- RequireDir::Loader
- Defined in:
- lib/require_dir/loader.rb
Overview
This class is meant to be instantiated per project/library, and then used to load en masse ruby files from a directory.
Class Attribute Summary collapse
-
.stderr ⇒ Object
Returns the value of attribute stderr.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#project_root ⇒ Object
Returns the value of attribute project_root.
Instance Method Summary collapse
- #debug? ⇒ Boolean
- #dir(folder, recursive = false) ⇒ Object (also: #require_dir)
- #dir_r(folder) ⇒ Object (also: #require_dir_r)
-
#initialize(root_dir, options = {}) ⇒ Loader
constructor
A new instance of Loader.
Constructor Details
#initialize(root_dir, options = {}) ⇒ Loader
Returns a new instance of Loader.
17 18 19 20 21 |
# File 'lib/require_dir/loader.rb', line 17 def initialize(root_dir, = {}) raise ArgumentError.new("Folder #{root_dir} is not found") unless Dir.exist?(root_dir) self.project_root = root_dir self. = end |
Class Attribute Details
.stderr ⇒ Object
Returns the value of attribute stderr.
12 13 14 |
# File 'lib/require_dir/loader.rb', line 12 def stderr @stderr end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/require_dir/loader.rb', line 9 def @options end |
#project_root ⇒ Object
Returns the value of attribute project_root.
9 10 11 |
# File 'lib/require_dir/loader.rb', line 9 def project_root @project_root end |
Instance Method Details
#debug? ⇒ Boolean
23 24 25 |
# File 'lib/require_dir/loader.rb', line 23 def debug? [:debug] || ENV['REQUIRE_DIR_DEBUG'] end |
#dir(folder, recursive = false) ⇒ Object Also known as: require_dir
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/require_dir/loader.rb', line 27 def dir(folder, recursive = false) folder = "/#{folder}" unless folder.start_with? '/' ::Dir.glob(project_root + folder + (recursive ? '/**/*.rb' : '/*.rb') ) do |file| puts "Loading #{file}" if debug? begin Kernel.require file rescue SyntaxError, LoadError => e report_error(e, file) raise(e) end end end |
#dir_r(folder) ⇒ Object Also known as: require_dir_r
40 41 42 |
# File 'lib/require_dir/loader.rb', line 40 def dir_r(folder) dir(folder, true) end |