Module: IiifPrint::Data::PathHelper
- Included in:
- WorkDerivatives, WorkFiles
- Defined in:
- lib/iiif_print/data/path_helper.rb
Overview
Mixin for methods related to paths on filesystem
Instance Method Summary collapse
- #isuri?(path) ⇒ Boolean
- #normalize_path(path) ⇒ Object
- #path_to_uri(path) ⇒ Object
- #registered_ingest_path(path) ⇒ Object
- #validate_path(path) ⇒ Object
Instance Method Details
#isuri?(path) ⇒ Boolean
12 13 14 |
# File 'lib/iiif_print/data/path_helper.rb', line 12 def isuri?(path) !path.scan(URI.regexp).empty? end |
#normalize_path(path) ⇒ Object
7 8 9 10 |
# File 'lib/iiif_print/data/path_helper.rb', line 7 def normalize_path(path) path = path.to_s isuri?(path) ? path : File.(path) end |
#path_to_uri(path) ⇒ Object
16 17 18 |
# File 'lib/iiif_print/data/path_helper.rb', line 16 def path_to_uri(path) isuri?(path) ? path : "file://#{path}" end |
#registered_ingest_path(path) ⇒ Object
20 21 22 23 24 |
# File 'lib/iiif_print/data/path_helper.rb', line 20 def registered_ingest_path(path) IiifPrint.config.registered_ingest_dirs.any? do |dir| path.start_with?(dir) && path.length > dir.length end end |
#validate_path(path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iiif_print/data/path_helper.rb', line 26 def validate_path(path) # treat file URIs equivalent to local paths path = File.(path.sub(/^file:\/\//, '')) # make sure file exists raise IOError, "Not found: #{path}" unless File.exist?(path) return if registered_ingest_path(path) # we cannot use path if it is not in the registered list for Hyrax ingest, we # would prefer to fail early vs. later+silently raise SecurityError, "Path specified is not configured in Hyrax ingest registered list: " \ "#{path}" end |