Class: Backup::FileItem::Cloud
- Inherits:
-
Base
- Object
- Base
- Backup::FileItem::Cloud
show all
- Defined in:
- lib/backup/file_item/cloud.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#file_hash, #semantic_path, #stat
Constructor Details
#initialize(args = {}) ⇒ Cloud
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/backup/file_item/cloud.rb', line 8
def initialize(args = {})
puts_fail "Empty hash in Cloud initialize method" if args.empty?
[:key, :secret, :bucket].each do |arg|
puts_fail "'#{arg.to_s.green}' should not be empty" if args[arg].nil?
instance_eval %{@#{arg} = args[:#{arg}]}
end
@timeout = 60
try_to_connect_with_cloud
end
|
Instance Attribute Details
#backet ⇒ Object
Returns the value of attribute backet.
6
7
8
|
# File 'lib/backup/file_item/cloud.rb', line 6
def backet
@backet
end
|
#key ⇒ Object
Returns the value of attribute key.
6
7
8
|
# File 'lib/backup/file_item/cloud.rb', line 6
def key
@key
end
|
#provider ⇒ Object
Returns the value of attribute provider.
6
7
8
|
# File 'lib/backup/file_item/cloud.rb', line 6
def provider
@provider
end
|
#secret ⇒ Object
Returns the value of attribute secret.
6
7
8
|
# File 'lib/backup/file_item/cloud.rb', line 6
def secret
@secret
end
|
#timeout ⇒ Object
Returns the value of attribute timeout.
6
7
8
|
# File 'lib/backup/file_item/cloud.rb', line 6
def timeout
@timeout
end
|
Instance Method Details
#create_directory_once(*directories) ⇒ Object
24
25
|
# File 'lib/backup/file_item/cloud.rb', line 24
def create_directory_once(*directories)
end
|
#create_file_once(file, data) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/backup/file_item/cloud.rb', line 47
def create_file_once(file, data)
try_to_work_with_cloud do
@directory.files.create(
:key => delete_slashes(file),
:body => data
)
end
end
|
#delete_dir(directory) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/backup/file_item/cloud.rb', line 34
def delete_dir directory
try_to_work_with_cloud do
path = delete_slashes(directory)
files = @directory.files.all(
:prefix => path,
:max_keys => 1_000_000_000
).map do |file|
file.destroy
end
end
end
|
#delete_file(path) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/backup/file_item/cloud.rb', line 27
def delete_file path
try_to_work_with_cloud do
file = delete_slashes(path)
@directory.files.get(file).destroy
end
end
|
#dir(path, mask = "*") ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/backup/file_item/cloud.rb', line 73
def dir(path, mask = "*")
path = delete_slashes(path)
mask = mask.gsub('.', '\.').gsub('*', '[^\/]')
files = @directory.files.all(
:prefix => path,
:max_keys => 1_000_000_000
).map(&:key)
files.map do |item|
match = item.match(/^#{path}\/([^\/]+#{mask}).*$/)
match[1] if match
end.compact.uniq
end
|
#exists?(file) ⇒ Boolean
56
57
58
59
60
61
62
63
|
# File 'lib/backup/file_item/cloud.rb', line 56
def exists? file
try_to_work_with_cloud do
!@directory.files.all(
:prefix => file,
:max_keys => 1
).nil?
end
end
|
#read_file(file) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/backup/file_item/cloud.rb', line 65
def read_file(file)
try_to_work_with_cloud do
file = delete_slashes(file)
remote_file = @directory.files.get(file)
remote_file.body if remote_file
end
end
|