Class: Riiif::AbstractFileSystemResolver

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/riiif/abstract_file_system_resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_path: nil) ⇒ AbstractFileSystemResolver

Returns a new instance of AbstractFileSystemResolver.



7
8
9
# File 'lib/riiif/abstract_file_system_resolver.rb', line 7

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

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



5
6
7
# File 'lib/riiif/abstract_file_system_resolver.rb', line 5

def base_path
  @base_path
end

#rootObject (readonly)

Returns the value of attribute root.



18
19
20
# File 'lib/riiif/abstract_file_system_resolver.rb', line 18

def root
  @root
end

Instance Method Details

#default_base_pathObject



11
12
13
14
15
16
# File 'lib/riiif/abstract_file_system_resolver.rb', line 11

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

#find(id) ⇒ Object



21
22
23
# File 'lib/riiif/abstract_file_system_resolver.rb', line 21

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

#path(id) ⇒ Object

Returns the path of the file.

Parameters:

  • id (String)

    the id to resolve

Returns:

  • the path of the file



27
28
29
30
# File 'lib/riiif/abstract_file_system_resolver.rb', line 27

def path(id)
  search = pattern(id)
  Dir.glob(search).first || raise(ImageNotFoundError, search)
end

#pattern(_id) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/riiif/abstract_file_system_resolver.rb', line 32

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