Class: Closync::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/closync/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, bucket_config = {}) ⇒ Storage

  • config (<~object) Closync::Config

  • bucket_config (<~hash) Options to initialize fog connection.

    • :provider (<~string): Options are [‘Local’, ‘AWS’, ‘Google’, ‘Rackspace’]

    • :directory (<~string) Bucket or local directory.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/closync/storage.rb', line 12

def initialize(config, bucket_config={})
  opts = bucket_config.clone
  dir = opts.delete(:directory)
  case opts[:provider]
  when 'Local'
    opts[:local_root] = config.working_dir
    @storage = Fog::Storage.new(opts)
  when 'AWS'
    opts[:aws_access_key_id] =
      config.credentials[:aws_access_key_id]
    opts[:aws_secret_access_key] =
      config.credentials[:aws_access_key_id]
    @storage = Fog::Storage.new(opts)
  when 'Google'
    opts[:google_storage_access_key_id] =
      config.credentials[:google_storage_access_key_id]
    opts[:google_storage_secret_access_key] =
      config.credentials[:google_storage_secret_access_key]
    @storage = Fog::Storage.new(opts)
  when 'Rackspace'
    opts[:rackspace_username] =
      config.credentials[:rackspace_username]
    opts[:rackspace_api_key] =
      config.credentials[:rackspace_api_key]
    @storage = Fog::Storage.new(opts)
  else
    raise 'Unsupported provider'
  end

  # Get the requested bucket/directory. Create if missing.
  if d = @storage.directories.get(dir)
    self.directory = d
  else
    @storage.directories.create(key: dir, public: true)
    self.directory = @storage.directories.get(dir)
  end
end

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



5
6
7
# File 'lib/closync/storage.rb', line 5

def directory
  @directory
end