Class: Fog::Storage
- Inherits:
-
Object
- Object
- Fog::Storage
- Defined in:
- lib/fog/storage.rb
Class Method Summary collapse
Class Method Details
.get_body_size(body) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/storage.rb', line 24 def self.get_body_size(body) if body.respond_to?(:force_encoding) body.force_encoding('BINARY') end if body.respond_to?(:bytesize) body.bytesize elsif body.respond_to?(:size) body.size elsif body.respond_to?(:stat) body.stat.size else 0 end end |
.new(attributes) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fog/storage.rb', line 4 def self.new(attributes) attributes = attributes.dup # prevent delete from having side effects case provider = attributes[:provider] # attributes.delete(:provider) when 'AWS' require 'fog/storage/aws' Fog::AWS::Storage.new(attributes) when 'Google' require 'fog/storage/google' Fog::Google::Storage.new(attributes) when 'Local' require 'fog/storage/local' Fog::Local::Storage.new(attributes) when 'Rackspace' require 'fog/storage/rackspace' Fog::Rackspace::Storage.new(attributes) else raise ArgumentError.new("#{provider} is not a recognized storage provider") end end |
.parse_data(data) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/storage.rb', line 39 def self.parse_data(data) = { :body => nil, :headers => {} } [:body] = data [:headers]['Content-Length'] = get_body_size(data) if data.respond_to?(:path) filename = ::File.basename(data.path) unless (mime_types = MIME::Types.of(filename)).empty? [:headers]['Content-Type'] = mime_types.first.content_type end end # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip end |