lib/nanoc/base/entities/item_rep.rb in nanoc-4.2.0 vs lib/nanoc/base/entities/item_rep.rb in nanoc-4.2.1

- old
+ new

@@ -1,8 +1,10 @@ module Nanoc::Int # @api private class ItemRep + include Nanoc::Int::ContractsSupport + # @return [Hash<Symbol,Nanoc::Int::Content>] attr_accessor :snapshot_contents # @return [Boolean] attr_accessor :compiled @@ -25,10 +27,11 @@ # @return [Boolean] attr_accessor :modified alias modified? modified + contract Nanoc::Int::Item, Symbol => C::Any # @param [Nanoc::Int::Item] item # # @param [Symbol] name def initialize(item, name) # Set primary attributes @@ -43,14 +46,16 @@ # Reset flags @compiled = false end + contract C::None => C::Bool def binary? @snapshot_contents[:last].binary? end + contract C::KeywordArgs[snapshot: C::Optional[C::Maybe[Symbol]]] => String # Returns the compiled content from a given snapshot. # # @param [Symbol] snapshot The name of the snapshot from which to # fetch the compiled content. By default, the returned compiled content # will be the content compiled right before the first layout call (if @@ -88,10 +93,11 @@ end @snapshot_contents[snapshot_name].string end + contract Symbol => C::Bool # Checks whether content exists at a given snapshot. # # @return [Boolean] True if content exists for the snapshot with the # given name, false otherwise # @@ -99,10 +105,11 @@ def snapshot?(snapshot_name) !@snapshot_contents[snapshot_name].nil? end alias has_snapshot? snapshot? + contract C::KeywordArgs[snapshot: C::Optional[Symbol]] => C::Maybe[String] # Returns the item rep’s raw path. It includes the path to the output # directory and the full filename. # # @param [Symbol] snapshot The snapshot for which the path should be # returned @@ -110,10 +117,11 @@ # @return [String] The item rep’s path def raw_path(snapshot: :last) @raw_paths[snapshot] end + contract C::KeywordArgs[snapshot: C::Optional[Symbol]] => C::Maybe[String] # Returns the item rep’s path, as used when being linked to. It starts # with a slash and it is relative to the output directory. It does not # include the path to the output directory. It will not include the # filename if the filename is an index filename. # @@ -123,17 +131,19 @@ # @return [String] The item rep’s path def path(snapshot: :last) @paths[snapshot] end + contract C::None => nil # Resets the compilation progress for this item representation. This is # necessary when an unmet dependency is detected during compilation. # # @api private # # @return [void] def forget_progress initialize_content + nil end # Returns an object that can be used for uniquely identifying objects. # # @api private