Sha256: 5ebe2e62b60f98e807faaa54346773cf6822abdf490710cedeed744d4e0e0c1a

Contents?: true

Size: 944 Bytes

Versions: 3

Compression:

Stored size: 944 Bytes

Contents

module Riiif
  class AbstractFileSystemResolver
    extend Deprecation
    attr_accessor :base_path

    def initialize(base_path: nil)
      @base_path = base_path || default_base_path
    end

    def default_base_path
      Deprecation.warn(self, 'Initializing a file resolver without setting the base path ' \
      'is deprecated and will be removed in Riiif 2.0', caller(2))
      @root ||= ::File.expand_path(::File.join(::File.dirname(__FILE__), '../..'))
      ::File.join(@root, 'spec/samples')
    end

    attr_reader :root
    deprecation_deprecate :root

    def find(id)
      Riiif::File.new(path(id))
    end

    # @param [String] id the id to resolve
    # @return the path of the file
    def path(id)
      search = pattern(id)
      Dir.glob(search).first || raise(ImageNotFoundError, search)
    end

    def pattern(_id)
      raise NotImplementedError, "Implement `pattern(id)' in the concrete class"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
riiif-1.7.1 lib/riiif/abstract_file_system_resolver.rb
riiif-2.0.0.beta1 app/resolvers/riiif/abstract_file_system_resolver.rb
riiif-1.7.0 lib/riiif/abstract_file_system_resolver.rb