Class: Backup::Storages::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/backup-agent/storages/local.rb

Defined Under Namespace

Classes: Object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory:) ⇒ Local

Returns a new instance of Local.



11
12
13
# File 'lib/backup-agent/storages/local.rb', line 11

def initialize(directory:)
  @directory = directory.gsub(/\/*\z/, "") # Ensure trailing slash
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



9
10
11
# File 'lib/backup-agent/storages/local.rb', line 9

def directory
  @directory
end

Instance Method Details

#delete(relative_path) ⇒ Object



21
22
23
# File 'lib/backup-agent/storages/local.rb', line 21

def delete(relative_path)
  FileUtils.rm_f(File.join(directory, relative_path))
end

#eachObject



25
26
27
28
29
# File 'lib/backup-agent/storages/local.rb', line 25

def each
  Dir.glob File.join(directory, "**", "*") do |path|
    yield Backup::Storages::Local::Object.new(self, path[directory.size+1..-1])
  end
end

#store(relative_path, file_to_write) ⇒ Object



15
16
17
18
19
# File 'lib/backup-agent/storages/local.rb', line 15

def store(relative_path, file_to_write)
  FileUtils.mkdir_p(directory)
  FileUtils.cp_r(file_to_write, File.join(directory, relative_path))
  Backup::Storages::Local::Object.new(self, relative_path)
end