Class: Backup::FileItem::Local
- Inherits:
-
Base
- Object
- Base
- Backup::FileItem::Local
show all
- Defined in:
- lib/backup/file_item/local.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#file_hash, #semantic_path, #stat
Constructor Details
#initialize ⇒ Local
Returns a new instance of Local.
8
9
10
|
# File 'lib/backup/file_item/local.rb', line 8
def initialize
@timeout = 0
end
|
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
6
7
8
|
# File 'lib/backup/file_item/local.rb', line 6
def timeout
@timeout
end
|
Instance Method Details
#create_directory_once(*directories) ⇒ Object
12
13
14
15
16
|
# File 'lib/backup/file_item/local.rb', line 12
def create_directory_once *directories
directories.each do |path|
FileUtils.mkdir_p(path) unless File.directory? path
end
end
|
#create_file_once(file, data) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/backup/file_item/local.rb', line 22
def create_file_once file, data
data = data.read if data.is_a? File or data.is_a? StringIO
File.open(file, 'wb') do |f|
f.print(data)
end unless File.exists?(file)
end
|
#delete_dir(directory) ⇒ Object
51
52
53
|
# File 'lib/backup/file_item/local.rb', line 51
def delete_dir directory
FileUtils.remove_dir directory
end
|
#delete_file(path) ⇒ Object
47
48
49
|
# File 'lib/backup/file_item/local.rb', line 47
def delete_file path
FileUtils.rm path
end
|
#dir(path, mask = "*") ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/backup/file_item/local.rb', line 38
def dir path, mask = "*"
r_mask = mask.gsub('.', '\.').gsub('*', '[^\/]')
Dir["#{path}/#{mask}"].map do |item|
match = item.match(/^#{path}\/([^\/]+#{r_mask}).*$/)
match[1] if match
end.compact.uniq
end
|
#exists?(file) ⇒ Boolean
18
19
20
|
# File 'lib/backup/file_item/local.rb', line 18
def exists? file
File.exists? file
end
|
#read_file(file) ⇒ Object
29
30
31
32
33
|
# File 'lib/backup/file_item/local.rb', line 29
def read_file file
File.open(file, 'rb') do |f|
f.read
end if File.exists? file
end
|