Class: Nanoc::Core::CompiledContentStore Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/compiled_content_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.

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initializeCompiledContentStore

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



9
10
11
12
# File 'lib/nanoc/core/compiled_content_store.rb', line 9

def initialize
  @contents = Hash.new { |hash, rep| hash[rep] = {} }
  @current_content = {}
end

Instance Method Details

#compiled_content(rep:, snapshot: nil) ⇒ 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.



66
67
68
69
70
71
72
73
74
# File 'lib/nanoc/core/compiled_content_store.rb', line 66

def compiled_content(rep:, snapshot: nil)
  snapshot_content = raw_compiled_content(rep:, snapshot:)

  if snapshot_content.binary?
    raise Nanoc::Core::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
  end

  snapshot_content.string
end

#get(rep, snapshot_name) ⇒ 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.



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

def get(rep, snapshot_name)
  @contents[rep][snapshot_name]
end

#get_all(rep) ⇒ 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.



35
36
37
# File 'lib/nanoc/core/compiled_content_store.rb', line 35

def get_all(rep)
  @contents[rep]
end

#get_current(rep) ⇒ 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.



20
21
22
# File 'lib/nanoc/core/compiled_content_store.rb', line 20

def get_current(rep)
  @current_content[rep]
end

#raw_compiled_content(rep:, snapshot: nil) ⇒ 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.



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

def raw_compiled_content(rep:, snapshot: nil)
  # Get name of last pre-layout snapshot
  has_pre = rep.snapshot_defs.any? { |sd| sd.name == :pre }
  snapshot_name = snapshot || (has_pre ? :pre : :last)

  # Check existance of snapshot
  snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
  unless snapshot_def
    raise Nanoc::Core::Errors::NoSuchSnapshot.new(rep, snapshot_name)
  end

  # Return content if it is available
  content = get(rep, snapshot_name)
  return content if content

  # Content is unavailable; notify and try again
  Fiber.yield(Nanoc::Core::Errors::UnmetDependency.new(rep, snapshot_name))
  get(rep, snapshot_name)
end

#set(rep, snapshot_name, contents) ⇒ 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.



25
26
27
# File 'lib/nanoc/core/compiled_content_store.rb', line 25

def set(rep, snapshot_name, contents)
  @contents[rep][snapshot_name] = contents
end

#set_all(rep, contents_per_snapshot) ⇒ 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/compiled_content_store.rb', line 40

def set_all(rep, contents_per_snapshot)
  @contents[rep] = contents_per_snapshot
end

#set_current(rep, content) ⇒ 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.



30
31
32
# File 'lib/nanoc/core/compiled_content_store.rb', line 30

def set_current(rep, content)
  @current_content[rep] = content
end