Class: PartialFinder::Graph

Inherits:
Object
  • Object
show all
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

AssumptionGraph

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(links) ⇒ Graph

Returns a new instance of Graph.

Raises:



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

Returns the value of attribute links.



14
15
16
# File 'lib/partial_finder/graph.rb', line 14

def links
  @links
end

#structureObject (readonly)

Returns the value of attribute structure.



14
15
16
# File 'lib/partial_finder/graph.rb', line 14

def structure
  @structure
end

Class Method Details

.from(path, root) ⇒ Object



30
31
32
# File 'lib/partial_finder/graph.rb', line 30

def self.from(path, root)
  new(LinkSet.new(path,root))
end

Instance Method Details

#to_sObject



34
35
36
# File 'lib/partial_finder/graph.rb', line 34

def to_s
  @to_s ||= Printer.new(self).string
end