class FileLocator
Attributes
source[R]
Public Class Methods
new(source)
click to toggle source
# File lib/file_locator.rb, line 22 def initialize(source) @source = source end
Public Instance Methods
attachment()
click to toggle source
# File lib/file_locator.rb, line 83 def attachment case uri.scheme when 's3' uri when 'file' File.open(location, 'r') else location end end
exist?()
click to toggle source
# File lib/file_locator.rb, line 60 def exist? case uri.scheme when 's3' S3File.new(uri).object.exists? when 'file' File.exist?(location) else false end end
Also aliased as: exists?
location()
click to toggle source
# File lib/file_locator.rb, line 49 def location case uri.scheme when 's3' S3File.new(uri).object.presigned_url(:get) when 'file' URI.decode(uri.path) else @uri.to_s end end
reader()
click to toggle source
# File lib/file_locator.rb, line 72 def reader case uri.scheme when 's3' S3File.new(uri).object.get.body when 'file' File.open(location, 'r') else Kernel.open(uri.to_s, 'r') end end
uri()
click to toggle source
# File lib/file_locator.rb, line 26 def uri if @uri.nil? if source.is_a? File @uri = Addressable::URI.parse("file://#{URI.encode(File.expand_path(source))}") else encoded_source = source begin @uri = Addressable::URI.parse(encoded_source) rescue URI::InvalidURIError if encoded_source == source encoded_source = URI.encode(encoded_source) retry else raise end end @uri = Addressable::URI.parse("file://#{URI.encode(File.expand_path(source))}") if @uri.scheme.nil? end end @uri end