module NewspaperWorks::Data::PathHelper
Mixin for methods related to paths on filesystem
Public Instance Methods
isuri?(path)
click to toggle source
# File lib/newspaper_works/data/path_helper.rb, line 12 def isuri?(path) !path.scan(URI.regexp).empty? end
normalize_path(path)
click to toggle source
# File lib/newspaper_works/data/path_helper.rb, line 7 def normalize_path(path) path = path.to_s isuri?(path) ? path : File.expand_path(path) end
path_to_uri(path)
click to toggle source
# File lib/newspaper_works/data/path_helper.rb, line 16 def path_to_uri(path) isuri?(path) ? path : "file://#{path}" end
validate_path(path)
click to toggle source
# File lib/newspaper_works/data/path_helper.rb, line 26 def validate_path(path) # treat file URIs equivalent to local paths path = File.expand_path(path.sub(/^file:\/\//, '')) # make sure file exists raise IOError, "Not found: #{path}" unless File.exist?(path) return if whitelisted_path(path) # we cannot use path if it is not whitelisted for Hyrax ingest, we # would prefer to fail early vs. later+silently raise SecurityError, "Path specified is not configured in Hyrax ingest whitelist: " \ "#{path}" end
whitelisted_path(path)
click to toggle source
# File lib/newspaper_works/data/path_helper.rb, line 20 def whitelisted_path(path) Hyrax.config.whitelisted_ingest_dirs.any? do |dir| path.start_with?(dir) && path.length > dir.length end end