Sha256: d767ec755cdbfd723df4ef3ba40f682a678cbc40cd2c489241991ecef3d385b9

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

module Nanoc::Int
  # Stores checksums for objects in order to be able to detect whether a file
  # has changed since the last site compilation.
  #
  # @api private
  class ChecksumStore < ::Nanoc::Int::Store
    include Nanoc::Int::ContractsSupport

    # @param [Nanoc::Int::Site] site
    def initialize(site: nil)
      super(Nanoc::Int::Store.tmp_path_for(env_name: (site.config.env_name if site), store_name: 'checksums'), 1)

      @site = site

      @checksums = {}
    end

    contract C::Any => C::Maybe[String]
    # Returns the old checksum for the given object. This makes sense for
    # items, layouts and code snippets.
    #
    # @param [#reference] obj The object for which to fetch the checksum
    #
    # @return [String] The checksum for the given object
    def [](obj)
      @checksums[obj.reference]
    end

    # Calculates and stores the checksum for the given object.
    def add(obj)
      if obj.is_a?(Nanoc::Int::Document)
        @checksums[[obj.reference, :content]] = Nanoc::Int::Checksummer.calc_for_content_of(obj)
        @checksums[[obj.reference, :attributes]] = Nanoc::Int::Checksummer.calc_for_attributes_of(obj)
      end

      @checksums[obj.reference] = Nanoc::Int::Checksummer.calc(obj)
    end

    contract C::Any => C::Maybe[String]
    def content_checksum_for(obj)
      @checksums[[obj.reference, :content]]
    end

    contract C::Any => C::Maybe[String]
    def attributes_checksum_for(obj)
      @checksums[[obj.reference, :attributes]]
    end

    protected

    def data
      @checksums
    end

    def data=(new_data)
      @checksums = new_data
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nanoc-4.4.4 lib/nanoc/base/repos/checksum_store.rb
nanoc-4.4.3 lib/nanoc/base/repos/checksum_store.rb
nanoc-4.4.2 lib/nanoc/base/repos/checksum_store.rb
nanoc-4.4.1 lib/nanoc/base/repos/checksum_store.rb
nanoc-4.4.0 lib/nanoc/base/repos/checksum_store.rb