Module: Comet::DSL::IncludeWalker

Defined in:
lib/comet/dsl/include_walker.rb

Class Method Summary collapse

Class Method Details

.includes_for(file, include_paths) ⇒ Object



5
6
7
# File 'lib/comet/dsl/include_walker.rb', line 5

def includes_for(file, include_paths)
  @@cache[[file, include_paths]]
end

.search(file, include_paths, visited) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/comet/dsl/include_walker.rb', line 9

def search(file, include_paths, visited)
  return visited[file] if visited.key? file

  includes = []

  File.read(file).scan(PATTERN) do
    header = Regexp.last_match[1] || Regexp.last_match[2]
    includes << find_included_file(header, include_paths)
  end

  visited[file] = []
  includes.compact.uniq.dup.each do |included|
    includes.concat search(included, include_paths, visited)
  end
  visited[file] = includes.compact.uniq
end