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.
34 35 36 37 38 39 40 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 34 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
28 29 30 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 28 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
24 25 26 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 24 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.
154 155 156 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 154 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
164 165 166 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 164 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
106 107 108 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 106 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).
123 124 125 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 123 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.
138 139 140 141 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 138 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 46 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| unless @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.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 70 def stop # Sanity check unless @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
159 160 161 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 159 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
85 86 87 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 85 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.
169 170 171 |
# File 'lib/nanoc/base/compilation/dependency_tracker.rb', line 169 def unload @graph = Nanoc::DirectedGraph.new([nil] + @objects) end |