Class: Nanoc::DependencyTracker Private
- Inherits:
-
Store
- Object
- Store
- Nanoc::DependencyTracker
- Defined in:
- lib/nanoc/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 Nanoc::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)
-
- (Nanoc::Compiler) compiler
private
The compiler that corresponds to this dependency tracker.
-
- (Array<Nanoc::Item, Nanoc::Layout>) objects
readonly
private
The list of items and layouts that are being tracked by the dependency tracker.
Attributes inherited from Store
Instance Method Summary (collapse)
-
- (void) forget_dependencies_for(object)
private
Empties the list of dependencies for the given object.
-
- (DependencyTracker) initialize(objects)
constructor
private
Creates a new dependency tracker for the given items and layouts.
-
- (Object) load_graph
deprecated
private
Deprecated.
Use Store#load instead
-
- (Array<Nanoc::Item, Nanoc::Layout, nil>) objects_causing_outdatedness_of(object)
private
Returns the direct dependencies for the given object.
-
- (Array<Nanoc::Item, Nanoc::Layout>) objects_outdated_due_to(object)
private
Returns the direct inverse dependencies for the given object.
-
- (void) record_dependency(src, dst)
private
Records a dependency from
src
todst
in the dependency graph. -
- (void) start
private
Starts listening for dependency messages (
:visit_started
and:visit_ended
) and start recording dependencies. -
- (void) stop
private
Stop listening for dependency messages and stop recording dependencies.
-
- (Object) store_graph
deprecated
private
Deprecated.
Use Store#store instead
-
- (Object) top
private
The topmost item on the stack, i.e.
-
- (Object) unload
private
Methods inherited from Store
#load, #no_data_found, #store, #version_mismatch_detected
Constructor Details
- (DependencyTracker) initialize(objects)
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/nanoc/base/compilation/dependency_tracker.rb', line 36 def initialize(objects) super('tmp/dependencies', 4) @objects = objects @graph = Nanoc::DirectedGraph.new([ nil ] + @objects) @stack = [] end |
Instance Attribute Details
- (Nanoc::Compiler) 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/nanoc/base/compilation/dependency_tracker.rb', line 30 def compiler @compiler end |
- (Array<Nanoc::Item, Nanoc::Layout>) objects (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/nanoc/base/compilation/dependency_tracker.rb', line 26 def objects @objects end |
Instance Method Details
- (void) forget_dependencies_for(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.
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.
156 157 158 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 156 def forget_dependencies_for(object) @graph.delete_edges_to(object) end |
- (Object) load_graph
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
166 167 168 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 166 def load_graph load end |
- (Array<Nanoc::Item, Nanoc::Layout, nil>) objects_causing_outdatedness_of(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.
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
108 109 110 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 108 def objects_causing_outdatedness_of(object) @graph.direct_predecessors_of(object) end |
- (Array<Nanoc::Item, Nanoc::Layout>) objects_outdated_due_to(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.
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).
125 126 127 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 125 def objects_outdated_due_to(object) @graph.direct_successors_of(object).compact end |
- (void) record_dependency(src, dst)
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.
140 141 142 143 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 140 def record_dependency(src, dst) # Warning! dst and src are *reversed* here! @graph.add_edge(dst, src) unless src == dst end |
- (void) start
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 65 66 67 |
# File 'lib/nanoc/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 Nanoc::NotificationCenter.on(:visit_started, self) do |obj| if !@stack.empty? Nanoc::NotificationCenter.post(:dependency_created, @stack.last, obj) record_dependency(@stack.last, obj) end @stack.push(obj) end # Register end of visits Nanoc::NotificationCenter.on(:visit_ended, self) do |obj| @stack.pop end end |
- (void) stop
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.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 72 def stop # Sanity check if !@stack.empty? raise 'Internal inconsistency: dependency tracker stack not empty at end of compilation' end # Unregister Nanoc::NotificationCenter.remove(:visit_started, self) Nanoc::NotificationCenter.remove(:visit_ended, self) end |
- (Object) store_graph
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
161 162 163 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 161 def store_graph store end |
- (Object) top
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 topmost item on the stack, i.e. the one currently being compiled
87 88 89 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 87 def top @stack.last end |
- (Object) unload
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.
171 172 173 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 171 def unload @graph = Nanoc::DirectedGraph.new([ nil ] + @objects) end |