Class: Backup::FileItem::Cloud

Inherits:
Base
  • Object
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

Returns a new instance of Cloud.



8
9
10
11
12
13
14
15
16
17
# 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

 try_to_connect_with_cloud 
end

Instance Attribute Details

#backetObject (readonly)

Returns the value of attribute backet.



6
7
8
# File 'lib/backup/file_item/cloud.rb', line 6

def backet
  @backet
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/backup/file_item/cloud.rb', line 6

def key
  @key
end

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/backup/file_item/cloud.rb', line 6

def provider
  @provider
end

#secretObject (readonly)

Returns the value of attribute secret.



6
7
8
# File 'lib/backup/file_item/cloud.rb', line 6

def secret
  @secret
end

Instance Method Details

#create_directory_once(*directories) ⇒ Object



19
20
21
# File 'lib/backup/file_item/cloud.rb', line 19

def create_directory_once(*directories)
  # Nothing happen
end

#create_file_once(file, data) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/backup/file_item/cloud.rb', line 23

def create_file_once(file, data)
  try_to_work_with_cloud do
    @directory.files.create(
      :key => delete_slashes(file),
      :body => data
    )
  end
end

#dir(path, mask = "*") ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/backup/file_item/cloud.rb', line 40

def dir(path, mask = "*")
  path = delete_slashes(path)
  mask = mask.gsub('.', '\.').gsub('*', '[^\/]')

  files = []
  
  files = @directory.files.all(
    :prefix => path,
    :max_keys => 30_000 #TODO: Fix or use it?
  ).map &:key
  
  files.map do |item|
    match = item.match(/^#{path}\/([^\/]+#{mask}).*$/)
    match[1] if match
  end.compact.uniq
end

#read_file(file) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/backup/file_item/cloud.rb', line 32

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