Module: Fog::Storage

Defined in:
lib/fog/storage.rb,
lib/fog/storage/aws.rb,
lib/fog/storage/local.rb,
lib/fog/storage/google.rb,
lib/fog/storage/rackspace.rb,
lib/fog/storage/models/aws/file.rb,
lib/fog/storage/models/aws/files.rb,
lib/fog/storage/models/local/file.rb,
lib/fog/storage/models/google/file.rb,
lib/fog/storage/models/local/files.rb,
lib/fog/storage/models/google/files.rb,
lib/fog/storage/models/aws/directory.rb,
lib/fog/storage/models/rackspace/file.rb,
lib/fog/storage/models/aws/directories.rb,
lib/fog/storage/models/local/directory.rb,
lib/fog/storage/models/rackspace/files.rb,
lib/fog/storage/models/google/directory.rb,
lib/fog/storage/requests/aws/get_bucket.rb,
lib/fog/storage/requests/aws/get_object.rb,
lib/fog/storage/requests/aws/list_parts.rb,
lib/fog/storage/requests/aws/put_bucket.rb,
lib/fog/storage/requests/aws/put_object.rb,
lib/fog/storage/requests/aws/sync_clock.rb,
lib/fog/storage/models/local/directories.rb,
lib/fog/storage/requests/aws/copy_object.rb,
lib/fog/storage/requests/aws/get_service.rb,
lib/fog/storage/requests/aws/head_object.rb,
lib/fog/storage/requests/aws/upload_part.rb,
lib/fog/storage/models/google/directories.rb,
lib/fog/storage/models/rackspace/directory.rb,
lib/fog/storage/requests/aws/delete_bucket.rb,
lib/fog/storage/requests/aws/delete_object.rb,
lib/fog/storage/requests/google/get_bucket.rb,
lib/fog/storage/requests/google/get_object.rb,
lib/fog/storage/requests/google/put_bucket.rb,
lib/fog/storage/requests/google/put_object.rb,
lib/fog/storage/requests/aws/get_bucket_acl.rb,
lib/fog/storage/requests/aws/get_object_acl.rb,
lib/fog/storage/requests/aws/get_object_url.rb,
lib/fog/storage/requests/aws/put_bucket_acl.rb,
lib/fog/storage/requests/aws/put_object_acl.rb,
lib/fog/storage/requests/aws/put_object_url.rb,
lib/fog/storage/requests/google/copy_object.rb,
lib/fog/storage/requests/google/get_service.rb,
lib/fog/storage/requests/google/head_object.rb,
lib/fog/storage/models/rackspace/directories.rb,
lib/fog/storage/requests/google/delete_bucket.rb,
lib/fog/storage/requests/google/delete_object.rb,
lib/fog/storage/requests/rackspace/get_object.rb,
lib/fog/storage/requests/rackspace/put_object.rb,
lib/fog/storage/requests/aws/get_bucket_policy.rb,
lib/fog/storage/requests/aws/put_bucket_policy.rb,
lib/fog/storage/requests/google/get_object_acl.rb,
lib/fog/storage/requests/google/get_object_url.rb,
lib/fog/storage/requests/google/put_bucket_acl.rb,
lib/fog/storage/requests/google/put_object_url.rb,
lib/fog/storage/requests/rackspace/head_object.rb,
lib/fog/storage/requests/aws/get_bucket_logging.rb,
lib/fog/storage/requests/aws/get_bucket_website.rb,
lib/fog/storage/requests/aws/get_object_torrent.rb,
lib/fog/storage/requests/aws/put_bucket_logging.rb,
lib/fog/storage/requests/aws/put_bucket_website.rb,
lib/fog/storage/requests/aws/get_bucket_location.rb,
lib/fog/storage/requests/aws/get_request_payment.rb,
lib/fog/storage/requests/aws/put_request_payment.rb,
lib/fog/storage/requests/rackspace/delete_object.rb,
lib/fog/storage/requests/rackspace/get_container.rb,
lib/fog/storage/requests/rackspace/put_container.rb,
lib/fog/storage/requests/aws/delete_bucket_policy.rb,
lib/fog/storage/requests/rackspace/get_containers.rb,
lib/fog/storage/requests/rackspace/head_container.rb,
lib/fog/storage/requests/aws/delete_bucket_website.rb,
lib/fog/storage/requests/aws/get_bucket_versioning.rb,
lib/fog/storage/requests/aws/put_bucket_versioning.rb,
lib/fog/storage/requests/google/get_object_torrent.rb,
lib/fog/storage/requests/rackspace/head_containers.rb,
lib/fog/storage/requests/aws/abort_multipart_upload.rb,
lib/fog/storage/requests/aws/list_multipart_uploads.rb,
lib/fog/storage/requests/rackspace/delete_container.rb,
lib/fog/storage/requests/aws/complete_multipart_upload.rb,
lib/fog/storage/requests/aws/initiate_multipart_upload.rb,
lib/fog/storage/requests/aws/post_object_hidden_fields.rb,
lib/fog/storage/requests/aws/get_bucket_object_versions.rb

Defined Under Namespace

Classes: AWS, Google, Local, Rackspace

Class Method Summary collapse

Class Method Details

.[](provider) ⇒ Object



4
5
6
# File 'lib/fog/storage.rb', line 4

def self.[](provider)
  self.new(:provider => provider)
end

.directoriesObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/storage.rb', line 28

def self.directories
  directories = []
  for provider in [:aws, :google, :local, :rackspace]
    begin
      directories.concat(self[provider].directories)
    rescue # ignore any missing credentials/etc
    end
  end
  directories
end

.get_body_size(body) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/storage.rb', line 39

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/storage.rb', line 8

def self.new(attributes)
  attributes = attributes.dup # prevent delete from having side effects
  case provider = attributes.delete(:provider).to_s.downcase.to_sym
  when :aws
    require 'fog/storage/aws'
    Fog::Storage::AWS.new(attributes)
  when :google
    require 'fog/storage/google'
    Fog::Storage::Google.new(attributes)
  when :local
    require 'fog/storage/local'
    Fog::Storage::Local.new(attributes)
  when :rackspace
    require 'fog/storage/rackspace'
    Fog::Storage::Rackspace.new(attributes)
  else
    raise ArgumentError.new("#{provider} is not a recognized storage provider")
  end
end

.parse_data(data) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/storage.rb', line 54

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