Class: Nanoc::Core::DependencyStore Private

Inherits:
Store
  • Object
show all
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_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::IterOf[Symbol], C::Bool]
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::IterOf[C::Or[String, Regexp]], 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

Attributes inherited from Store

#filename, #version

Instance Method Summary collapse

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.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nanoc/core/dependency_store.rb', line 19

def initialize(items, layouts, config)
  super(Nanoc::Core::Store.tmp_path_for(config: config, store_name: 'dependencies'), 5)

  @config = config
  @items = items
  @layouts = layouts

  rebuild_refs2objs

  @new_objects = []
  @graph = Nanoc::Core::DirectedGraph.new([nil] + objs2refs(@items) + objs2refs(@layouts))
end

Instance Attribute Details

#itemsObject

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.



15
16
17
# File 'lib/nanoc/core/dependency_store.rb', line 15

def items
  @items
end

#layoutsObject

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.



16
17
18
# File 'lib/nanoc/core/dependency_store.rb', line 16

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.



126
127
128
# File 'lib/nanoc/core/dependency_store.rb', line 126

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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nanoc/core/dependency_store.rb', line 42

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,
      Nanoc::Core::DependencyProps.new(
        raw_content: props.fetch(:raw_content, false),
        attributes: props.fetch(:attributes, false),
        compiled_content: props.fetch(:compiled_content, false),
        path: props.fetch(:path, false),
      ),
    )
  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.

Parameters:



139
140
141
# File 'lib/nanoc/core/dependency_store.rb', line 139

def forget_dependencies_for(object)
  @graph.delete_edges_to(obj2ref(object))
end

#new_itemsObject

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.



69
70
71
# File 'lib/nanoc/core/dependency_store.rb', line 69

def new_items
  @new_objects.select { |o| o.is_a?(Nanoc::Core::Item) }
end

#new_layoutsObject

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.



73
74
75
# File 'lib/nanoc/core/dependency_store.rb', line 73

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

Parameters:

Returns:



94
95
96
# File 'lib/nanoc/core/dependency_store.rb', line 94

def objects_causing_outdatedness_of(object)
  refs2objs(@graph.direct_predecessors_of(obj2ref(object)))
end

#rebuild_refs2objsObject

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.



32
33
34
35
36
37
38
39
# File 'lib/nanoc/core/dependency_store.rb', line 32

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.

Parameters:



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/nanoc/core/dependency_store.rb', line 110

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)

  existing_props = Nanoc::Core::DependencyProps.new(**(@graph.props_for(dst_ref, src_ref) || {}))
  new_props = Nanoc::Core::DependencyProps.new(raw_content: raw_content, attributes: attributes, compiled_content: compiled_content, path: path)
  props = existing_props.merge(new_props)

  @graph.add_edge(dst_ref, src_ref, props: props.to_h)
end