Class: Nanoc::Core::DependencyStore Private
- Includes:
- ContractsSupport
- Defined in:
- lib/nanoc/core/dependency_store.rb
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.
Constant Summary collapse
- C_RAW_CONTENT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
C::Or[ C::ArrayOf[C::Or[String, Regexp]], C::Bool ]
- C_ATTR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
C::Or[ C::ArrayOf[Symbol], C::HashOf[Symbol => C::Any], C::Bool ]
- C_KEYWORD_PROPS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
C::KeywordArgs[ raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTR], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool] ]
- C_OBJ_SRC =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Nanoc::Core::Item
- C_OBJ_DST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
C::Or[ Nanoc::Core::Item, Nanoc::Core::Layout, Nanoc::Core::Configuration, Nanoc::Core::IdentifiableCollection ]
Instance Attribute Summary collapse
- #items ⇒ Object private
- #layouts ⇒ Object private
Attributes inherited from Store
Instance Method Summary collapse
- #add_vertex_for(obj) ⇒ Object private
- #dependencies_causing_outdatedness_of(object) ⇒ Object private
-
#forget_dependencies_for(object) ⇒ void
private
Empties the list of dependencies for the given object.
-
#initialize(items, layouts, config) ⇒ DependencyStore
constructor
private
A new instance of DependencyStore.
- #new_items ⇒ Object private
- #new_layouts ⇒ Object private
-
#objects_causing_outdatedness_of(object) ⇒ Array<Nanoc::Core::Item, Nanoc::Core::Layout, nil>
private
Returns the direct dependencies for the given object.
- #rebuild_refs2objs ⇒ Object private
-
#record_dependency(src, dst, raw_content: false, attributes: false, compiled_content: false, path: false) ⇒ void
private
Records a dependency from ‘src` to `dst` in the dependency graph.
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
Methods inherited from Store
#load, #store, tmp_path_for, tmp_path_prefix
Constructor Details
#initialize(items, layouts, config) ⇒ DependencyStore
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 a new instance of DependencyStore.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/nanoc/core/dependency_store.rb', line 44 def initialize(items, layouts, config) super(Nanoc::Core::Store.tmp_path_for(config:, store_name: 'dependencies'), 6) @config = config @items = items @layouts = layouts rebuild_refs2objs @new_objects = [] @graph = Nanoc::Core::DirectedGraph.new([nil] + objs2refs(@items) + objs2refs(@layouts)) end |
Instance Attribute Details
#items ⇒ 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.
40 41 42 |
# File 'lib/nanoc/core/dependency_store.rb', line 40 def items @items end |
#layouts ⇒ 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.
41 42 43 |
# File 'lib/nanoc/core/dependency_store.rb', line 41 def layouts @layouts end |
Instance Method Details
#add_vertex_for(obj) ⇒ 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.
151 152 153 |
# File 'lib/nanoc/core/dependency_store.rb', line 151 def add_vertex_for(obj) @refs2objs[obj2ref(obj)] = obj end |
#dependencies_causing_outdatedness_of(object) ⇒ 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.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/nanoc/core/dependency_store.rb', line 67 def dependencies_causing_outdatedness_of(object) objects_causing_outdatedness_of(object).map do |other_object| props = props_for(other_object, object) Nanoc::Core::Dependency.new( other_object, object, props, ) end end |
#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.
164 165 166 |
# File 'lib/nanoc/core/dependency_store.rb', line 164 def forget_dependencies_for(object) @graph.delete_edges_to(obj2ref(object)) end |
#new_items ⇒ 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.
89 90 91 |
# File 'lib/nanoc/core/dependency_store.rb', line 89 def new_items @new_objects.select { |o| o.is_a?(Nanoc::Core::Item) } end |
#new_layouts ⇒ 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.
93 94 95 |
# File 'lib/nanoc/core/dependency_store.rb', line 93 def new_layouts @new_objects.select { |o| o.is_a?(Nanoc::Core::Layout) } end |
#objects_causing_outdatedness_of(object) ⇒ Array<Nanoc::Core::Item, Nanoc::Core::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
114 115 116 |
# File 'lib/nanoc/core/dependency_store.rb', line 114 def objects_causing_outdatedness_of(object) refs2objs(@graph.direct_predecessors_of(obj2ref(object))) end |
#rebuild_refs2objs ⇒ 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.
57 58 59 60 61 62 63 64 |
# File 'lib/nanoc/core/dependency_store.rb', line 57 def rebuild_refs2objs @refs2objs = {} @items.each { |o| add_vertex_for(o) } @layouts.each { |o| add_vertex_for(o) } add_vertex_for(@config) add_vertex_for(@items) add_vertex_for(@layouts) end |
#record_dependency(src, dst, raw_content: false, attributes: false, compiled_content: false, path: false) ⇒ 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.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/nanoc/core/dependency_store.rb', line 130 def record_dependency(src, dst, raw_content: false, attributes: false, compiled_content: false, path: false) return if src == dst add_vertex_for(src) add_vertex_for(dst) src_ref = obj2ref(src) dst_ref = obj2ref(dst) # Convert attributes into key-value pairs, if necessary if attributes.is_a?(Hash) attributes = attributes.to_a end existing_props = @graph.props_for(dst_ref, src_ref) new_props = Nanoc::Core::DependencyProps.new(raw_content:, attributes:, compiled_content:, path:) props = existing_props ? existing_props.merge(new_props) : new_props @graph.add_edge(dst_ref, src_ref, props:) end |