Sha256: f65cd89bcb930212f3a39584522cc68736c0f72d25db6925c06f896563696f52

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

require 'digest/sha2'

module Hanko
  class Fingerprint
    class << self
      attr_writer :digest_class

      def pon(assets_dir, source)
        cached_pon[source] ||= generate_pon(assets_dir, source)
      end

      def digest_class=(klass)
        @cached_pon = {}
        @digest_class = klass
      end

      private

      def cached_pon
        @cached_pon ||= {}
      end

      def generate_pon(assets_dir, source)
        path = File.join(assets_dir || '', source)
        File.file?(path) ? file_digest(path) : ''
      end

      def file_digest(path)
        digest_class.file(path).hexdigest
      end

      def digest_class
        @digest_class || ::Digest::SHA256
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanko-0.1.3 lib/hanko/fingerprint.rb