Class: Teapot::Extractors::PreprocessorExtractor

Inherits:
Graph::Extractor show all
Defined in:
lib/teapot/extractors/preprocessor_extractor.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Graph::Extractor

#call

Constructor Details

#initialize(patterns, roots = []) ⇒ PreprocessorExtractor

Returns a new instance of PreprocessorExtractor.



39
40
41
42
43
# File 'lib/teapot/extractors/preprocessor_extractor.rb', line 39

def initialize(patterns, roots = [])
	super patterns
	
	@roots = roots
end

Class Method Details

.include_directories(flags) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/teapot/extractors/preprocessor_extractor.rb', line 26

def self.include_directories(flags)
	roots = []

	# Extract include directories:
	flags.each do |option|
		if option.to_s =~ /^-I(.+)/
			roots << Pathname($1)
		end
	end

	return roots
end

Instance Method Details

#extract(path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/teapot/extractors/preprocessor_extractor.rb', line 45

def extract(path)
	local_root = Pathname(path).dirname

	File.open(path).each do |line|
		if line =~ /\#(?:include|import) "(.*?)"/
			path = local_root + $1
		
			yield path if path.exist?
		elsif line =~ /\#(?:include|import) \<(.*?)\>/
			path = @roots.collect{|root| root+$1}.find{|path| path.exist?}
		
			yield path if path
		end
	end
end