Class: Backup::Storage::Yandex::Disk

Inherits:
Base
  • Object
show all
Defined in:
lib/yandex/disk/backup/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, storage_id = nil, &block) ⇒ Disk

Returns a new instance of Disk.



11
12
13
14
15
# File 'lib/yandex/disk/backup/storage.rb', line 11

def initialize(model, storage_id = nil, &block)
  super
  instance_eval(&block) if block_given?
  @path ||= '/backups'
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/yandex/disk/backup/storage.rb', line 9

def access_token
  @access_token
end

Instance Method Details

#connectionObject



17
18
19
# File 'lib/yandex/disk/backup/storage.rb', line 17

def connection
  ::Yandex::Disk::Client.new(:access_token => access_token, :timeout => 500)
end

#remove!(package) ⇒ Object



32
33
34
35
36
# File 'lib/yandex/disk/backup/storage.rb', line 32

def remove!(package)
  Logger.info "Removing backup package dated #{ package.time }..."
  remote_path = remote_path_for(package)
  connection.delete(remote_path)
end

#storage_nameObject



38
39
40
# File 'lib/yandex/disk/backup/storage.rb', line 38

def storage_name
  'Yandex::Disk'
end

#transfer!Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/yandex/disk/backup/storage.rb', line 21

def transfer!
  disk = connection
  disk.mkdir_p(remote_path)
  package.filenames.each do |filename|
    src = File.join(Config.tmp_path, filename)
    dest = File.join(remote_path, filename)
    Logger.info "Storing '#{ dest }'..."
    disk.put!(src, dest)
  end
end