Sha256: e45c137e92e5e7f0d114b2ac496afffd9be01240077a4e22e4c65d9154888d04

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

# frozen_string_literal: true

require "openssl"

module Hanami
  module Assets
    # Bundle assets from a single application.
    #
    # @since 0.1.0
    # @api private
    class Bundler
      # @since 0.3.0
      # @api private
      class Asset
        # @since 0.3.0
        # @api private
        attr_reader :path

        # @since 0.3.0
        # @api private
        attr_reader :configuration

        # @since 0.3.0
        # @api private
        WILDCARD_EXT = ".*"

        # Return a new instance
        #
        # @since 0.3.0
        # @api private
        def initialize(path, configuration)
          @path = path
          @configuration = configuration
        end

        # @since 0.3.0
        # @api private
        def expanded_path
          ::File.expand_path(@path)
        end

        # @since 0.3.0
        # @api private
        def fingerprinted_target
          ::File.join(directory, "#{filename}-#{fingerprint}#{extension}")
        end

        # @since 0.3.0
        # @api private
        def expanded_fingerprinted_target
          ::File.expand_path(fingerprinted_target)
        end

        # @since 0.3.0
        # @api private
        def base64_digest(algorithm)
          raw_digest(algorithm).base64digest
        end

        private

        # @since 0.3.0
        # @api private
        def directory
          ::File.dirname(@path)
        end

        # @since 0.3.0
        # @api private
        def filename
          ::File.basename(@path, WILDCARD_EXT)
        end

        # @since 0.3.0
        # @api private
        def extension
          ::File.extname(@path)
        end

        # @since 0.3.0
        # @api private
        def fingerprint
          raw_digest(:md5).hexdigest
        end

        # @since 0.3.0
        # @api private
        def raw_digest(algorithm)
          OpenSSL::Digest.new(algorithm.to_s, contents)
        end

        # @since 0.3.0
        # @api private
        def contents
          ::File.read(@path)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-assets-1.3.5 lib/hanami/assets/bundler/asset.rb