Class: Codependency::Graph

Inherits:
Hash
  • Object
show all
Includes:
TSort
Defined in:
lib/codependency/graph.rb

Instance Method Summary collapse

Instance Method Details

#filesObject

Returns the sorted list of files as determined by this graph, relative to the calling file.



35
36
37
# File 'lib/codependency/graph.rb', line 35

def files
  tsort
end

#parserObject

The file parser for this dependency graph.



47
48
49
# File 'lib/codependency/graph.rb', line 47

def parser
  @parser ||= Parser.new
end

#pathObject

The path set for this dependency graph.



41
42
43
# File 'lib/codependency/graph.rb', line 41

def path
  @path ||= Path.new parser.extensions
end

#require(file) ⇒ Object Also known as: <<

Add the given file to this graph. Creates a new entry in the graph, the key of which is the relative path to this file and the value is the array of relative paths to its dependencies. Any dependent files will also be recursively added to this graph.



12
13
14
15
16
17
18
19
# File 'lib/codependency/graph.rb', line 12

def require( file )
  return if key?( file )

  self[ file ] = deps( file )
  self[ file ].each do |dependency|
    self.require dependency
  end
end

#scan(glob) ⇒ Object

Parses all of the files in the given glob and adds their dependencies to the graph. A file in this glob is not added to the graph unless another file in the glob depends on it.



26
27
28
29
30
# File 'lib/codependency/graph.rb', line 26

def scan( glob )
  Dir[ glob ].flat_map { |f| deps( f ) }.uniq.each do |dependency|
    self.require dependency
  end
end