class URI::S3
Public Instance Methods
open(*args) { |object| ... }
click to toggle source
@return [AWS::S3::S3Object] S3
object (quacks like IO)
# File lib/open-uri-s3.rb, line 9 def open(*args) options = {} options[:use_ssl] = false if ENV['AWS_USE_SSL'] == 'false' if ENV["AWS_S3_ENDPOINT"] s3_endpoint_uri = URI(ENV['AWS_S3_ENDPOINT']) AWS.config(s3_endpoint: s3_endpoint_uri.host, s3_port: s3_endpoint_uri.port) end s3 = ::AWS::S3.new(options) bucket = s3.buckets[self.hostname] if !ENV['AWS_S3_ENDPOINT'] && bucket.location_constraint s3_endpoint = "s3-#{bucket.location_constraint}.amazonaws.com" s3 = ::AWS::S3.new(options.update(s3_endpoint: s3_endpoint)) bucket = s3.buckets[self.hostname] end path = self.path[1..-1] object = bucket.objects[path] if block_given? yield object else object end end
read()
click to toggle source
# File lib/open-uri-s3.rb, line 35 def read open(to_s).read end