Module: Fog::Storage

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

Defined Under Namespace

Classes: AWS, Google, Local, Ninefold, 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



31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/storage.rb', line 31

def self.directories
  directories = []
  for provider in self.providers
    begin
      directories.concat(self[provider].directories)
    rescue # ignore any missing credentials/etc
    end
  end
  directories
end

.get_body_size(body) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/storage.rb', line 42

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
27
28
29
# 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/aws/storage'
    Fog::Storage::AWS.new(attributes)
  when :google
    require 'fog/google/storage'
    Fog::Storage::Google.new(attributes)
  when :local
    require 'fog/local/storage'
    Fog::Storage::Local.new(attributes)
  when :ninefold
    require 'fog/ninefold/storage'
    Fog::Storage::Ninefold.new(attributes)
  when :rackspace
    require 'fog/rackspace/storage'
    Fog::Storage::Rackspace.new(attributes)
  else
    raise ArgumentError.new("#{provider} is not a recognized storage provider")
  end
end

.parse_data(data) ⇒ Object



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

def self.parse_data(data)
   = {
    :body => nil,
    :headers => {}
  }

  [:body] = data
  [:headers]['Content-Length'] = get_body_size(data)

  if data.respond_to?(:path) and !data.path.nil?
    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

.providersObject



76
77
78
# File 'lib/fog/storage.rb', line 76

def self.providers
  Fog.services[:storage]
end