Sha256: f51f4158c36feb9428e1ba44dd90ac95fce4a7afe661270afa2c254ce1a0b26f

Contents?: true

Size: 760 Bytes

Versions: 1

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

class Shoes
  module Common
    module ImageHandling
      def absolute_file_path(path)
        if Pathname(path).absolute?
          search_for(File.basename(path), File.dirname(path))
        else
          search_for(path, *default_search_paths)
        end
      end

      def search_for(path, *locations)
        found = locations.map { |dir| File.join(dir, path) }
                         .find { |candidate| File.exist?(candidate) }

        unless found
          raise FileNotFoundError, "#{path} not found. Searched #{locations.join(',')}"
        end

        found
      end

      def default_search_paths
        [Dir.pwd, Shoes.configuration.app_dir, File.join(Shoes::DIR, "static")]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-core-4.0.0.rc1 lib/shoes/common/image_handling.rb