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_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.

C::Or[
  nil,
  Nanoc::Core::Item,
  Nanoc::Core::Layout,
  Nanoc::Core::Configuration,
  Nanoc::Core::IdentifiableCollection,
]
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.

Nanoc::Core::Item

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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nanoc/core/dependency_store.rb', line 47

def initialize(items, layouts, config)
  super(
    self.class.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

#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.



41
42
43
# File 'lib/nanoc/core/dependency_store.rb', line 41

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.



42
43
44
# File 'lib/nanoc/core/dependency_store.rb', line 42

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.



184
185
186
# File 'lib/nanoc/core/dependency_store.rb', line 184

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.



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/nanoc/core/dependency_store.rb', line 75

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

#dependencies_outdated_because_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.



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/nanoc/core/dependency_store.rb', line 88

def dependencies_outdated_because_of(object)
  objects_outdated_because_of(object).map do |other_object|
    props = props_for(object, other_object)

    Nanoc::Core::Dependency.new(
      object,
      other_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.

Parameters:



197
198
199
# File 'lib/nanoc/core/dependency_store.rb', line 197

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.



110
111
112
# File 'lib/nanoc/core/dependency_store.rb', line 110

def new_items
  @new_objects.grep(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.



114
115
116
# File 'lib/nanoc/core/dependency_store.rb', line 114

def new_layouts
  @new_objects.grep(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:



135
136
137
# File 'lib/nanoc/core/dependency_store.rb', line 135

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

#objects_outdated_because_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.



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

def objects_outdated_because_of(object)
  refs2objs(@graph.direct_successors_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.



65
66
67
68
69
70
71
72
# File 'lib/nanoc/core/dependency_store.rb', line 65

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 src is oudated, dst will also become outdated.

Parameters:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/nanoc/core/dependency_store.rb', line 158

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(src_ref, dst_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(src_ref, dst_ref, props:)
end