Class: Yarrow::Content::Expansion::Traversal
- Inherits:
-
Object
- Object
- Yarrow::Content::Expansion::Traversal
- Defined in:
- lib/yarrow/content/expansion/traversal.rb
Instance Attribute Summary collapse
-
#aggregator ⇒ Object
readonly
Returns the value of attribute aggregator.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#policy ⇒ Object
readonly
Returns the value of attribute policy.
Instance Method Summary collapse
- #complete_traversal ⇒ Object
- #expand ⇒ Object
-
#initialize(graph, policy) ⇒ Traversal
constructor
A new instance of Traversal.
-
#source_node ⇒ Object
If source path represents entire content dir, then include the entire content dir instead of scanning from a subfolder matching the name of the collection.
- #start_traversal ⇒ Object
- #visit_directory(dir_node) ⇒ Object
- #visit_file(file_node) ⇒ Object
- #visit_source(root_node) ⇒ Object
Constructor Details
#initialize(graph, policy) ⇒ Traversal
Returns a new instance of Traversal.
7 8 9 10 11 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 7 def initialize(graph, policy) @graph = graph @policy = policy @aggregator = policy.aggregator_const.new(graph) end |
Instance Attribute Details
#aggregator ⇒ Object (readonly)
Returns the value of attribute aggregator.
5 6 7 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 5 def aggregator @aggregator end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
5 6 7 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 5 def graph @graph end |
#policy ⇒ Object (readonly)
Returns the value of attribute policy.
5 6 7 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 5 def policy @policy end |
Instance Method Details
#complete_traversal ⇒ Object
43 44 45 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 43 def complete_traversal aggregator.after_traversal(policy) end |
#expand ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 47 def start_traversal traversal = source_node.depth_first.each visit_source(traversal.next) loop do node = traversal.next case node.label when :directory then visit_directory(node) when :file then visit_file(node) end end complete_traversal end |
#source_node ⇒ Object
If source path represents entire content dir, then include the entire content dir instead of scanning from a subfolder matching the name of the collection.
16 17 18 19 20 21 22 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 16 def source_node if policy.source_path == "." graph.n(:root).out(:directory) else graph.n(name: policy.source_path) end end |
#start_traversal ⇒ Object
39 40 41 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 39 def start_traversal aggregator.before_traversal(policy) end |
#visit_directory(dir_node) ⇒ Object
28 29 30 31 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 28 def visit_directory(dir_node) # TODO: match on potential directory extension/filter aggregator.(dir_node, policy) end |
#visit_file(file_node) ⇒ Object
33 34 35 36 37 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 33 def visit_file(file_node) # TODO: dispatch underscore prefix or index files separately # TODO: match on file extension aggregator.(file_node, policy) end |
#visit_source(root_node) ⇒ Object
24 25 26 |
# File 'lib/yarrow/content/expansion/traversal.rb', line 24 def visit_source(root_node) aggregator.(root_node, policy) end |