Class: PartialFinder::Graph
- Inherits:
-
Object
- Object
- PartialFinder::Graph
- Defined in:
- lib/partial_finder/graph.rb
Overview
The Graph object assembles individual chain links into a structure that better resembles the multiple render paths of a partial.
Specifically, using hash syntax, the structure looks something like: { original_partial => [{ parent1 => […] }, { parent2 => […] }, “terminating_view_file”] } In this example, the partial is directly rendered by “terminating_view_file” and has a deeper rendering chain up to 2 other parents somewhere.
Chains will terminate in a string instead of an array (ie, the parent will be a string). These strings presumably will be either a controller or a view, but if the partial is unused, it could also terminate in itself or another partial.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(links) ⇒ Graph
constructor
A new instance of Graph.
- #to_s ⇒ Object
Constructor Details
#initialize(links) ⇒ Graph
Returns a new instance of Graph.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/partial_finder/graph.rb', line 16 def initialize(links) raise NonLinkArgument.new(links) unless links.is_a? LinkSet @links = links if links.any? # The usage of 'root' is a side-effect of how #assemble_links works. # If given the initial link instead of a new 'root' link, only the first # parent of { partial => [parent1, parent2, ...] } will be traversed. @structure = assemble_links(Link.new('root', links.first.child)).parent else @structure = [] end end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
14 15 16 |
# File 'lib/partial_finder/graph.rb', line 14 def links @links end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
14 15 16 |
# File 'lib/partial_finder/graph.rb', line 14 def structure @structure end |