Class: DepGraph::GraphCreator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_type = :none) ⇒ GraphCreator

Returns a new instance of GraphCreator.



11
12
13
14
15
# File 'lib/graph_creator.rb', line 11

def initialize(node_type = :none)
  @node_finder = get_node_finder(node_type)
  @graph_image_creator_class = GraphImageCreator
  @trans = false
end

Instance Attribute Details

#from=(value) ⇒ Object (writeonly)

Sets the attribute from

Parameters:

  • value

    the value to set the attribute from to.



9
10
11
# File 'lib/graph_creator.rb', line 9

def from=(value)
  @from = value
end

#graph_image_creator_class=(value) ⇒ Object (writeonly)

Sets the attribute graph_image_creator_class

Parameters:

  • value

    the value to set the attribute graph_image_creator_class to.



9
10
11
# File 'lib/graph_creator.rb', line 9

def graph_image_creator_class=(value)
  @graph_image_creator_class = value
end

#node_finder=(value) ⇒ Object (writeonly)

Sets the attribute node_finder

Parameters:

  • value

    the value to set the attribute node_finder to.



9
10
11
# File 'lib/graph_creator.rb', line 9

def node_finder=(value)
  @node_finder = value
end

#to=(value) ⇒ Object (writeonly)

Sets the attribute to

Parameters:

  • value

    the value to set the attribute to to.



9
10
11
# File 'lib/graph_creator.rb', line 9

def to=(value)
  @to = value
end

#trans=(value) ⇒ Object (writeonly)

Sets the attribute trans

Parameters:

  • value

    the value to set the attribute trans to.



9
10
11
# File 'lib/graph_creator.rb', line 9

def trans=(value)
  @trans = value
end

Class Method Details

.typesObject



17
18
19
20
21
22
# File 'lib/graph_creator.rb', line 17

def self.types
  node_finders_dir = File.join(File.dirname(__FILE__), 'nodefinders')
  node_finders = Dir.glob(File.join(node_finders_dir, '*_node_finder.rb'))
  node_finders = node_finders.map {|nf| nf.gsub(node_finders_dir + '/', '').gsub('_node_finder.rb', '').to_sym}
  return DependencyTypesManager.types + node_finders
end

Instance Method Details

#create_graphObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/graph_creator.rb', line 36

def create_graph
  nodes = @node_finder.get_nodes.uniq
  nodes = apply_filters(nodes)
  nodes = remove_disconnected_nodes(nodes)

  graph = @graph_image_creator_class.new            
  return graph if nodes.size < 2

  nodes.each do |node|
    graph.add_node(node)
  end
  
  nodes.each do |node|
    node.dependencies.each do |dependable|
      graph.add_edge(node, dependable) if nodes.include? dependable
    end
  end
  
  graph.trans = @trans
  
  return graph
end

#create_image(image_file_name = 'dependency_graph.png') ⇒ Object



32
33
34
# File 'lib/graph_creator.rb', line 32

def create_image(image_file_name = 'dependency_graph.png')
  create_graph.create_image(image_file_name) 
end

#excluded_nodes=(exc) ⇒ Object



28
29
30
# File 'lib/graph_creator.rb', line 28

def excluded_nodes=(exc)
  @excluded_nodes = exc.map {|e| e.strip}
end

#location=(loc) ⇒ Object



24
25
26
# File 'lib/graph_creator.rb', line 24

def location=(loc)
  @node_finder.location = loc
end