Class: ActiverecordCallbackLens::Graph::GraphBuilder
- Inherits:
-
Object
- Object
- ActiverecordCallbackLens::Graph::GraphBuilder
- Defined in:
- lib/activerecord_callback_lens/graph/graph_builder.rb
Overview
Converts an array of parsed CallbackDefinition objects into a Graph.
Each definition becomes a CallbackNode. When a definition has a condition_tree, the tree is walked recursively and mapped onto graph nodes:
AndNode / OrNode -> ConditionNode, then recurse into children
NotNode -> no node; recurse into the child (negation is dropped
for the v0.1 dependency view)
PredicateNode -> PredicateNode graph node
MethodRefNode -> MethodNode; recurse into expanded_tree when present
Every condition/predicate/method node gets a :requires edge pointing at its parent (the callback or enclosing combinator), so edges flow from a dependency up to the thing that depends on it.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Graph::Graph
-
#initialize(definitions) ⇒ GraphBuilder
constructor
A new instance of GraphBuilder.
Constructor Details
#initialize(definitions) ⇒ GraphBuilder
Returns a new instance of GraphBuilder.
30 31 32 33 34 35 |
# File 'lib/activerecord_callback_lens/graph/graph_builder.rb', line 30 def initialize(definitions) @definitions = definitions @nodes = [] @edges = [] @counter = 0 end |
Class Method Details
.build(definitions) ⇒ Graph::Graph
25 26 27 |
# File 'lib/activerecord_callback_lens/graph/graph_builder.rb', line 25 def self.build(definitions) new(definitions).build end |
Instance Method Details
#build ⇒ Graph::Graph
38 39 40 41 |
# File 'lib/activerecord_callback_lens/graph/graph_builder.rb', line 38 def build @definitions.each { |definition| add_callback(definition) } Graph.new(nodes: @nodes, edges: @edges) end |