Class: CodeNode::GraphBuilder
- Inherits:
-
Object
- Object
- CodeNode::GraphBuilder
- Defined in:
- lib/code_node/graph_builder.rb
Overview
Helps to build an IR::Graph
Instance Attribute Summary collapse
-
#graph ⇒ IR::Graph
readonly
The graph being built.
Instance Method Summary collapse
-
#define(&block) ⇒ self
Define the custom graph generation rules.
-
#finalize ⇒ nil
Apply styles and prune the graph.
-
#find_nodes ⇒ self
Search the sources for nodes.
-
#find_relations ⇒ nil
Search the sources for relations.
-
#initialize(name, parser) ⇒ GraphBuilder
constructor
A new instance of GraphBuilder.
-
#render ⇒ nil
Render the graph.
-
#sources ⇒ Array<String>
Paths to ruby source files.
Constructor Details
#initialize(name, parser) ⇒ GraphBuilder
Returns a new instance of GraphBuilder.
14 15 16 17 18 19 |
# File 'lib/code_node/graph_builder.rb', line 14 def initialize(name, parser) @name = name @graph = IR::Graph.new @parser = parser @sexp = [] # array of file sexp, one per file end |
Instance Attribute Details
#graph ⇒ IR::Graph (readonly)
Returns the graph being built.
10 11 12 |
# File 'lib/code_node/graph_builder.rb', line 10 def graph @graph end |
Instance Method Details
#define(&block) ⇒ self
Define the custom graph generation rules
28 29 30 31 |
# File 'lib/code_node/graph_builder.rb', line 28 def define(&block) block.call DSL::GraphDefiner.new(@graph) self end |
#finalize ⇒ nil
Apply styles and prune the graph
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/code_node/graph_builder.rb', line 51 def finalize # Apply styles before pruning because some relations may be destroyed while pruning puts "Applying styles" @graph.apply_styles # Prune the graph according to ignore rules. # We keep pruning until there are no more changes because some rules don't apply the first time (for example: &:island?) puts "Pruning nodes" i = 1 while (x = @graph.prune) > 0 puts " #{x} nodes pruned on #{i.ordinalize} pass" i += 1 end self end |
#find_nodes ⇒ self
Search the sources for nodes
35 36 37 38 39 |
# File 'lib/code_node/graph_builder.rb', line 35 def find_nodes puts '1st pass: find nodes' find :nodes self end |
#find_relations ⇒ nil
Search the sources for relations
43 44 45 46 47 |
# File 'lib/code_node/graph_builder.rb', line 43 def find_relations puts '2nd pass: find relations' find :relations self end |
#render ⇒ nil
Render the graph
69 70 71 72 73 74 75 76 |
# File 'lib/code_node/graph_builder.rb', line 69 def render # Activate code_node while rendering templates # so that cog will be able to find code_node templates Cog.activate_tool 'code_node' do stamp 'code_node/graph.dot', "#{@name}.dot" end nil end |
#sources ⇒ Array<String>
Returns paths to ruby source files.
22 23 24 |
# File 'lib/code_node/graph_builder.rb', line 22 def sources Dir.glob("#{Cog.project_source_path}/**/*.rb") end |