Sha256: 30d588ce5e1fca2bf846dd4cbf6811b4a72a0e07ec56366e9f3f1a541980adba

Contents?: true

Size: 1.07 KB

Versions: 21

Compression:

Stored size: 1.07 KB

Contents

# This sorts out the issues of require'ing files in Ruby
#	1) on one line, you specify all the paths you need
# 2) Relative paths will be relative to the file you are in, absolute paths also supported
# 3) Paths will be expanded
# 4) Paths will only be added if they don't already exist
# 
module ::Kernel

	# returns full path given relative to $LOAD_PATH
	def require_which(aFilepath)
		aFilepath += '.rb'
		$LOAD_PATH.each do |dir|
			full_path = File.expand_path(File.join(dir,aFilepath))
			return full_path if File.exist? full_path
		end
		return nil
	end

	def require_paths(*aArgs)
	  caller_dir = File.dirname(File.expand_path(caller.first.sub(/:[0-9]+.*/,'')))
		aArgs.each do |aPath|
			aPath = File.expand_path(aPath,caller_dir)
			$LOAD_PATH << aPath unless $LOAD_PATH.include?(aPath)
		end
	end
	
	def require_paths_first(*aArgs)
	  caller_dir = File.dirname(File.expand_path(caller.first.sub(/:[0-9]+.*/,'')))
		paths = []
		aArgs.each do |aPath|
			aPath = File.expand_path(aPath,caller_dir)
			paths << aPath
		end
		paths.each do |p|
			$LOAD_PATH.insert(0,p)
		end
	end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
buzzcore-0.6.6 lib/buzzcore/require_paths.rb
buzzcore-0.6.4 lib/buzzcore/require_paths.rb
buzzcore-0.6.3 lib/buzzcore/require_paths.rb
buzzcore-0.6.2 lib/buzzcore/require_paths.rb
buzzcore-0.6.1 lib/buzzcore/require_paths.rb
buzzcore-0.5.1 lib/buzzcore/require_paths.rb
buzzcore-0.5.0 lib/buzzcore/require_paths.rb
buzzcorej-0.0.2 lib/buzzcorej/require_paths.rb
buzzcore-0.4.3 lib/buzzcore/require_paths.rb
buzzcore-0.4.2 lib/buzzcore/require_paths.rb
buzzcore-0.4.1 lib/buzzcore/require_paths.rb
buzzcore-0.4.0 lib/buzzcore/require_paths.rb
buzzcore-0.3.5 lib/buzzcore/require_paths.rb
buzzcore-0.3.4 lib/buzzcore/require_paths.rb
buzzcore-0.3.3 lib/buzzcore/require_paths.rb
buzzcore-0.3.2 lib/buzzcore/require_paths.rb
buzzcore-0.3.1 lib/buzzcore/require_paths.rb
buzzcore-0.3.0 lib/buzzcore/require_paths.rb
buzzcore-0.2.7 lib/buzzcore/require_paths.rb
buzzcore-0.2.6 lib/buzzcore/require_paths.rb