Class: Nanoc3::DependencyTracker Private
- Defined in:
- lib/nanoc3/base/compilation/dependency_tracker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for remembering dependencies between items and layouts. It is used to speed up compilation by only letting an item be recompiled when it is outdated or any of its dependencies (or dependencies’ dependencies, etc) is outdated.
The dependencies tracked by the dependency tracker are not dependencies based on an item’s or a layout’s content. When one object uses an attribute of another object, then this is also treated as a dependency. While dependencies based on an item’s or layout’s content (handled in Compiler) cannot be mutually recursive, the more general dependencies in Nanoc3::DependencyTracker can (e.g. item A can use an attribute of item B and vice versa without problems).
The dependency tracker remembers the dependency information between runs. Dependency information is stored in the ‘tmp/dependencies` file.
Instance Attribute Summary collapse
-
#compiler ⇒ Nanoc3::Compiler
private
The compiler that corresponds to this dependency tracker.
-
#objects ⇒ Array<Nanoc3::Item, Nanoc3::Layout>
readonly
private
The list of items and layouts that are being tracked by the dependency tracker.
Attributes inherited from Store
Instance Method Summary collapse
-
#forget_dependencies_for(object) ⇒ void
private
Empties the list of dependencies for the given object.
-
#initialize(objects) ⇒ DependencyTracker
constructor
private
Creates a new dependency tracker for the given items and layouts.
-
#load_graph ⇒ Object
deprecated
private
Deprecated.
Use Store#load instead
-
#objects_causing_outdatedness_of(object) ⇒ Array<Nanoc3::Item, Nanoc3::Layout, nil>
private
Returns the direct dependencies for the given object.
-
#objects_outdated_due_to(object) ⇒ Array<Nanoc3::Item, Nanoc3::Layout>
private
Returns the direct inverse dependencies for the given object.
-
#record_dependency(src, dst) ⇒ void
private
Records a dependency from ‘src` to `dst` in the dependency graph.
-
#start ⇒ void
private
Starts listening for dependency messages (‘:visit_started` and `:visit_ended`) and start recording dependencies.
-
#stop ⇒ void
private
Stop listening for dependency messages and stop recording dependencies.
-
#store_graph ⇒ Object
deprecated
private
Deprecated.
Use Store#store instead
- #unload ⇒ Object private
Methods inherited from Store
#load, #no_data_found, #store, #version_mismatch_detected
Constructor Details
#initialize(objects) ⇒ DependencyTracker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new dependency tracker for the given items and layouts.
36 37 38 39 40 41 42 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 36 def initialize(objects) super('tmp/dependencies', 4) @objects = objects @graph = Nanoc3::DirectedGraph.new([ nil ] + @objects) end |
Instance Attribute Details
#compiler ⇒ Nanoc3::Compiler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The compiler that corresponds to this dependency tracker.
30 31 32 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 30 def compiler @compiler end |
#objects ⇒ Array<Nanoc3::Item, Nanoc3::Layout> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The list of items and layouts that are being tracked by the dependency tracker.
26 27 28 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 26 def objects @objects end |
Instance Method Details
#forget_dependencies_for(object) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Empties the list of dependencies for the given object. This is necessary before recompiling the given object, because otherwise old dependencies will stick around and new dependencies will appear twice. This function removes all incoming edges for the given vertex.
140 141 142 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 140 def forget_dependencies_for(object) @graph.delete_edges_to(object) end |
#load_graph ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use Store#load instead
150 151 152 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 150 def load_graph self.load end |
#objects_causing_outdatedness_of(object) ⇒ Array<Nanoc3::Item, Nanoc3::Layout, nil>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the direct dependencies for the given object.
The direct dependencies of the given object include the items and layouts that, when outdated will cause the given object to be marked as outdated. Indirect dependencies will not be returned (e.g. if A depends on B which depends on C, then the direct dependencies of A do not include C).
The direct predecessors can include nil, which indicates an item that is no longer present in the site.
predecessors of
the given object
92 93 94 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 92 def objects_causing_outdatedness_of(object) @graph.direct_predecessors_of(object) end |
#objects_outdated_due_to(object) ⇒ Array<Nanoc3::Item, Nanoc3::Layout>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the direct inverse dependencies for the given object.
The direct inverse dependencies of the given object include the objects that will be marked as outdated when the given object is outdated. Indirect dependencies will not be returned (e.g. if A depends on B which depends on C, then the direct inverse dependencies of C do not include A).
109 110 111 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 109 def objects_outdated_due_to(object) @graph.direct_successors_of(object).compact end |
#record_dependency(src, dst) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records a dependency from ‘src` to `dst` in the dependency graph. When `dst` is oudated, `src` will also become outdated.
124 125 126 127 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 124 def record_dependency(src, dst) # Warning! dst and src are *reversed* here! @graph.add_edge(dst, src) unless src == dst end |
#start ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Starts listening for dependency messages (‘:visit_started` and `:visit_ended`) and start recording dependencies.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 48 def start # Initialize dependency stack. An object will be pushed onto this stack # when it is visited. Therefore, an object on the stack always depends # on all objects pushed above it. @stack = [] # Register start of visits Nanoc3::NotificationCenter.on(:visit_started, self) do |obj| self.record_dependency(@stack[-1], obj) unless @stack.empty? @stack.push(obj) end # Register end of visits Nanoc3::NotificationCenter.on(:visit_ended, self) do |obj| @stack.pop end end |
#stop ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Stop listening for dependency messages and stop recording dependencies.
69 70 71 72 73 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 69 def stop # Unregister Nanoc3::NotificationCenter.remove(:visit_started, self) Nanoc3::NotificationCenter.remove(:visit_ended, self) end |
#store_graph ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Use Store#store instead
145 146 147 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 145 def store_graph self.store end |
#unload ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 |
# File 'lib/nanoc3/base/compilation/dependency_tracker.rb', line 155 def unload @graph = Nanoc3::DirectedGraph.new([ nil ] + @objects) end |