Class: Dabcup::Storage::Driver::Local
- Defined in:
- lib/dabcup/storage/driver/local.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #connect ⇒ Object
- #delete(file_name) ⇒ Object
- #disconnect ⇒ Object
- #get(remote_name, local_path) ⇒ Object
-
#initialize(url) ⇒ Local
constructor
A new instance of Local.
- #list ⇒ Object
- #local? ⇒ Boolean
- #protocol ⇒ Object
- #put(local_path, remote_name) ⇒ Object
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.(url.sub('file://', '')) end |
Instance Method Details
#connect ⇒ Object
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 |
#disconnect ⇒ Object
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 |
#list ⇒ Object
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
46 47 48 |
# File 'lib/dabcup/storage/driver/local.rb', line 46 def local? true end |
#protocol ⇒ Object
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 |