lib/file_locator.rb in active_encode-0.5.0 vs lib/file_locator.rb in active_encode-0.6.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require 'addressable/uri'
require 'aws-sdk'
class FileLocator
attr_reader :source
@@ -8,11 +9,11 @@
attr_reader :bucket, :key
def initialize(uri)
uri = Addressable::URI.parse(uri)
@bucket = URI.decode(uri.host)
- @key = URI.decode(uri.path).sub(%r(^/*(.+)/*$),'\1')
+ @key = URI.decode(uri.path).sub(%r{^/*(.+)/*$}, '\1')
end
def object
@object ||= Aws::S3::Object.new(bucket_name: bucket, key: key)
end
@@ -37,13 +38,11 @@
else
raise
end
end
- if @uri.scheme.nil?
- @uri = Addressable::URI.parse("file://#{URI.encode(File.expand_path(source))}")
- end
+ @uri = Addressable::URI.parse("file://#{URI.encode(File.expand_path(source))}") if @uri.scheme.nil?
end
end
@uri
end
@@ -66,28 +65,28 @@
File.exist?(location)
else
false
end
end
- alias_method :exists?, :exist?
+ alias exists? exist?
def reader
case uri.scheme
when 's3'
S3File.new(uri).object.get.body
when 'file'
- File.open(location,'r')
+ File.open(location, 'r')
else
- Kernel::open(uri.to_s, 'r')
+ Kernel.open(uri.to_s, 'r')
end
end
def attachment
case uri.scheme
when 's3'
uri
when 'file'
- File.open(location,'r')
+ File.open(location, 'r')
else
location
end
end
end