Module: LoadPath
- Defined in:
- lib/load_path.rb
Overview
This module makes the setting up of the load path for Ruby projects easy by the use of a simple configure() block. Also your statements to setup the load path look cleaner and clearer
See the README.md file for detailed examples.
Author: Nayyara Samuel ([email protected])
Defined Under Namespace
Classes: LoadPathSetup
Class Method Summary collapse
-
.calling_class_path(call_stack) ⇒ Object
Construct the file location/path of the file that is using this module.
-
.configure(&block) ⇒ Object
Primary method to setup your load path.
Class Method Details
.calling_class_path(call_stack) ⇒ Object
Construct the file location/path of the file that is using this module
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/load_path.rb', line 21 def self.calling_class_path(call_stack) me = __FILE__ configure_call_index = call_stack.rindex { |call| call =~ /#{me}.*\:in.*configure/ } external_call = call_stack[configure_call_index + 1] begin external_file_name = (external_call.match /(.*):\d+:in/)[1] external_file_directory = File.(File.dirname(external_file_name)) rescue raise "Cannot infer calling file's name from #{external_call}" end return external_file_directory end |
.configure(&block) ⇒ Object
Primary method to setup your load path
13 14 15 16 17 18 |
# File 'lib/load_path.rb', line 13 def self.configure(&block) root = calling_class_path(caller(0)) # Evaluate the block on an instance of the load path setup # that understand the files required LoadPathSetup.new(root).instance_eval(&block) end |