Class: ImportGraph::DepGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/import_graph/dep_graph.rb

Overview

Source of truth for the dependency graph for the provided directory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, dir_path) ⇒ DepGraph

Returns a new instance of DepGraph.



8
9
10
11
12
# File 'lib/import_graph/dep_graph.rb', line 8

def initialize(graph, dir_path)
  @graph = graph
  @dependees = {}
  @dir_path = dir_path
end

Instance Attribute Details

#graphObject

Returns the value of attribute graph.



6
7
8
# File 'lib/import_graph/dep_graph.rb', line 6

def graph
  @graph
end

Instance Method Details

#get_dependee_files(file_path) ⇒ Object

Get all the files that depend on this file



22
23
24
25
26
27
28
29
30
31
# File 'lib/import_graph/dep_graph.rb', line 22

def get_dependee_files(file_path)
  return @dependees[file_path] if @dependees.has_key? file_path

  @dependees[file_path] = Set.new
  @graph.keys.each do |key|
    @dependees[file_path].add key if @graph[key].include? file_path
  end

  @dependees[file_path]
end

#get_dependent_files(file_path) ⇒ Object

Get all the files that this file depends on



15
16
17
18
19
# File 'lib/import_graph/dep_graph.rb', line 15

def get_dependent_files(file_path)
  return nil unless @graph.has_key? file_path

  @graph[file_path]
end