Sha256: 00c37d6249f2930c5b219a8911edc7b7035240ee6d4b5886495198c1257ffec7

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

require 'hanami/utils/load_paths'
require 'hanami/utils/file_list'

module Hanami
  module Assets
    # Configuration settings
    #
    # @since 0.1.0
    # @api private
    module Config
      # Source directories for a specific application
      #
      # @since 0.1.0
      # @api private
      #
      # @see Hanami::Assets.duplicate
      # @see http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/LoadPaths
      #
      # TODO The perf of this class is poor, consider to improve it.
      class Sources < Utils::LoadPaths
        # @since 0.3.0
        # @api private
        SKIPPED_FILE_PREFIX = '_'.freeze

        # @since 0.1.0
        # @api private
        attr_writer :root

        # @since 0.1.0
        # @api private
        def initialize(root)
          super()
          @root = root
        end

        # @since 0.1.0
        # @api private
        def map
          [].tap do |result|
            each do |source|
              result << yield(source)
            end
          end
        end

        # @since 0.1.0
        # @api private
        def find(filename)
          result = files(filename).first
          result = Pathname.new(result) unless result.nil?
          result
        end

        # @since 0.1.0
        # @api private
        def files(name = nil)
          result = []

          Utils::FileList[map { |source| "#{source}#{::File::SEPARATOR}**#{::File::SEPARATOR}#{name}*" }].each do |file|
            next if ::File.directory?(file) || ::File.basename(file).start_with?(SKIPPED_FILE_PREFIX)
            result << file
          end

          result
        end

        private

        # @since 0.1.0
        # @api private
        def realpath(path)
          @root.join(path).realpath
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hanami-assets-1.3.0.beta1 lib/hanami/assets/config/sources.rb
hanami-assets-1.2.0 lib/hanami/assets/config/sources.rb
hanami-assets-1.2.0.rc2 lib/hanami/assets/config/sources.rb
hanami-assets-1.2.0.rc1 lib/hanami/assets/config/sources.rb
hanami-assets-1.2.0.beta2 lib/hanami/assets/config/sources.rb
hanami-assets-1.2.0.beta1 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.1 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.0 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.0.rc1 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.0.beta3 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.0.beta2 lib/hanami/assets/config/sources.rb
hanami-assets-1.1.0.beta1 lib/hanami/assets/config/sources.rb
hanami-assets-1.0.0 lib/hanami/assets/config/sources.rb
hanami-assets-1.0.0.rc1 lib/hanami/assets/config/sources.rb