Class: Dabcup::Storage::Driver::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/dabcup/storage/driver/local.rb

Instance Attribute Summary

Attributes inherited from Base

#uri

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Local

Returns a new instance of Local.



9
10
11
12
# File 'lib/dabcup/storage/driver/local.rb', line 9

def initialize(url)
  super(url)
  @path = File.expand_path(url.sub('file://', ''))
end

Instance Method Details

#connectObject

Raises:

  • (DabcupError)


38
39
40
41
# File 'lib/dabcup/storage/driver/local.rb', line 38

def connect
  FileUtils.mkpath(@path) if not File.exist?(@path)
  raise DabcupError.new("The path '#{@path}' is not a directory.") if not File.directory?(@path)
end

#delete(file_name) ⇒ Object



33
34
35
36
# File 'lib/dabcup/storage/driver/local.rb', line 33

def delete(file_name)
  file_path = File.join(@path, file_name)
  File.delete(file_path)
end

#disconnectObject



43
44
# File 'lib/dabcup/storage/driver/local.rb', line 43

def disconnect
end

#get(remote_name, local_path) ⇒ Object



19
20
21
22
23
# File 'lib/dabcup/storage/driver/local.rb', line 19

def get(remote_name, local_path)
  connect
  remote_path = File.join(@path, remote_name)
  FileUtils.copy(remote_path, local_path)
end

#listObject



25
26
27
28
29
30
31
# File 'lib/dabcup/storage/driver/local.rb', line 25

def list
  dumps = []
  Dir.foreach(@path) do |name|
    dumps << Dump.new(:name => name, :size => File.size(File.join(@path, name)))
  end
  dumps
end

#local?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dabcup/storage/driver/local.rb', line 46

def local?
  true
end

#protocolObject



5
6
7
# File 'lib/dabcup/storage/driver/local.rb', line 5

def protocol
  'file'
end

#put(local_path, remote_name) ⇒ Object



14
15
16
17
# File 'lib/dabcup/storage/driver/local.rb', line 14

def put(local_path, remote_name)
  remote_path = File.join(@path, remote_name)
  FileUtils.copy(local_path, remote_path)
end