Module: LoadPath

Defined in:
lib/load_path.rb,
lib/version.rb,
lib/path_builder.rb

Overview

Author: Nayyara Samuel ([email protected])

Defined Under Namespace

Classes: LoadPathSetup, PathBuilder, PathHelper

Constant Summary collapse

VERSION =
'0.2.1'

Class Method Summary collapse

Class Method Details

.calling_class_path(call_stack) ⇒ Object

Construct the file location/path of the file that is using this module



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/load_path.rb', line 23

def self.calling_class_path(call_stack)
  me = __FILE__
  configure_call_index = call_stack.index { |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.expand_path(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



15
16
17
18
19
20
# File 'lib/load_path.rb', line 15

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