lib/nanoc/base/repos/compiled_content_cache.rb in nanoc-4.4.4 vs lib/nanoc/base/repos/compiled_content_cache.rb in nanoc-4.4.5
- old
+ new
@@ -2,42 +2,38 @@
# Represents a cache than can be used to store already compiled content,
# to prevent it from being needlessly recompiled.
#
# @api private
class CompiledContentCache < ::Nanoc::Int::Store
+ include Nanoc::Int::ContractsSupport
+
+ contract C::KeywordArgs[env_name: C::Maybe[String], items: C::IterOf[Nanoc::Int::Item]] => C::Any
def initialize(env_name: nil, items:)
super(Nanoc::Int::Store.tmp_path_for(env_name: env_name, store_name: 'compiled_content'), 2)
@items = items
@cache = {}
end
- # Returns the cached compiled content for the given item
- # representation. This cached compiled content is a hash where the keys
- # are the snapshot names and the values the compiled content at the
- # given snapshot.
+ contract Nanoc::Int::ItemRep => C::Maybe[C::HashOf[Symbol => Nanoc::Int::Content]]
+ # Returns the cached compiled content for the given item representation.
#
- # @param [Nanoc::Int::ItemRep] rep The item rep to fetch the content for
- #
- # @return [Hash<Symbol,String>] A hash containing the cached compiled
- # content for the given item representation
+ # This cached compiled content is a hash where the keys are the snapshot
+ # names. and the values the compiled content at the given snapshot.
def [](rep)
item_cache = @cache[rep.item.identifier] || {}
item_cache[rep.name]
end
+ contract Nanoc::Int::ItemRep, C::HashOf[Symbol => Nanoc::Int::Content] => self
# Sets the compiled content for the given representation.
#
- # @param [Nanoc::Int::ItemRep] rep The item representation for which to set
- # the compiled content
- #
- # @param [Hash<Symbol,String>] content A hash containing the compiled
- # content of the given representation
- #
- # @return [void]
+ # This cached compiled content is a hash where the keys are the snapshot
+ # names. and the values the compiled content at the given snapshot.
def []=(rep, content)
@cache[rep.item.identifier] ||= {}
@cache[rep.item.identifier][rep.name] = content
+ self
end
protected
def data