Module: Where

Extended by:
Where
Included in:
Where
Defined in:
lib/where.rb

Instance Method Summary collapse

Instance Method Details

#cdir(depth = 0) ⇒ Object



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

def cdir(depth = 0)
	if f = cfile(depth + 1)
		f.parent
	else
		Pathname.new('.')
	end
end

#cfile(depth = 0) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/where.rb', line 6

def cfile(depth = 0)
	p = caller[depth][/^[^:]+(?=:)/]
	if /^\(\w+\)$/ === p
		nil
	else
		Pathname.new p
	end
end

#cgem(depth = 0) ⇒ Object



23
24
25
26
27
# File 'lib/where.rb', line 23

def cgem(depth = 0)
	require 'rubygems'
	f = cfile(depth + 1).to_s
	Gem::Specification.find {|s| f.start_with? s.gem_dir }
end

#cgem_path(rel_path = '', depth = 0) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/where.rb', line 29

def cgem_path(rel_path = '', depth = 0)
	if gem = cgem(depth + 1)
		Pathname.new(gem.gem_dir)
	else
		Pathname.new('.')
	end + rel_path
end