Class: Dabcup::Storage
- Inherits:
-
Object
show all
- Defined in:
- lib/dabcup/storage.rb,
lib/dabcup/storage/dump.rb,
lib/dabcup/storage/driver/s3.rb,
lib/dabcup/storage/driver/ftp.rb,
lib/dabcup/storage/driver/base.rb,
lib/dabcup/storage/driver/sftp.rb,
lib/dabcup/storage/driver/local.rb
Defined Under Namespace
Modules: Driver
Classes: Dump
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url) ⇒ Storage
Returns a new instance of Storage.
17
18
19
|
# File 'lib/dabcup/storage.rb', line 17
def initialize(url)
@driver = Driver.build(url)
end
|
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
15
16
17
|
# File 'lib/dabcup/storage.rb', line 15
def driver
@driver
end
|
#rules ⇒ Object
Returns the value of attribute rules.
15
16
17
|
# File 'lib/dabcup/storage.rb', line 15
def rules
@rules
end
|
Instance Method Details
#array_of_dumps_names(dump_or_string_or_array) ⇒ Object
Returns an array of String representing dumps names. If the argument is an array it must contains only String or Dump objects.
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/dabcup/storage.rb', line 77
def array_of_dumps_names(dump_or_string_or_array)
case dump_or_string_or_array
when String
[dump_or_string_or_array]
when Dump
[dump_or_string_or_array.name]
when Array
dump_or_string_or_array.map do |dump_or_string|
case dump_or_string
when String
dump_or_string
when Dump
dump_or_string.name
else
raise ArgumentError.new("Expecting an array of String or Dump instead of #{dump_or_string.class}")
end
end
else
raise ArgumentError.new("Expecting a String or Dump or and Array instead of #{dump_or_string_or_array.class}")
end
end
|
#clear ⇒ Object
51
52
53
|
# File 'lib/dabcup/storage.rb', line 51
def clear
delete(list)
end
|
#default_port(port) ⇒ Object
71
72
73
|
# File 'lib/dabcup/storage.rb', line 71
def default_port(port)
@port = port if @port.nil? or @port.empty?
end
|
#delete(dump_or_string_or_array) ⇒ Object
46
47
48
49
|
# File 'lib/dabcup/storage.rb', line 46
def delete(dump_or_string_or_array)
file_names = array_of_dumps_names(dump_or_string_or_array)
file_names.each { |file_name| @driver.delete(file_name) }
end
|
#disconnect ⇒ Object
25
26
27
|
# File 'lib/dabcup/storage.rb', line 25
def disconnect
@driver.disconnect
end
|
#dump_name?(name) ⇒ Boolean
59
60
61
|
# File 'lib/dabcup/storage.rb', line 59
def dump_name?(name)
return false
end
|
#exists?(name) ⇒ Boolean
55
56
57
|
# File 'lib/dabcup/storage.rb', line 55
def exists?(name)
list.any? { |dump| dump.name == name }
end
|
#find_by_name(file_name) ⇒ Object
63
64
65
|
# File 'lib/dabcup/storage.rb', line 63
def find_by_name(file_name)
list.find { |dump| dump.name == file_name }
end
|
#get(remote_name, local_path) ⇒ Object
37
38
39
|
# File 'lib/dabcup/storage.rb', line 37
def get(remote_name, local_path)
@driver.get(remote_name, local_path)
end
|
#list ⇒ Object
41
42
43
44
|
# File 'lib/dabcup/storage.rb', line 41
def list
dumps = @driver.list.inject([]) { |array, dump| dump.valid? ? array << dump : array }
dumps.sort { |left, right| left.created_at <=> right.created_at }
end
|
#local? ⇒ Boolean
29
30
31
|
# File 'lib/dabcup/storage.rb', line 29
def local?
@driver.local?
end
|
#name ⇒ Object
67
68
69
|
# File 'lib/dabcup/storage.rb', line 67
def name
"#{@login}@#{@host}:#{port}:#{@path}"
end
|
#path ⇒ Object
21
22
23
|
# File 'lib/dabcup/storage.rb', line 21
def path
@driver.path
end
|
#put(local_path, remote_name) ⇒ Object
33
34
35
|
# File 'lib/dabcup/storage.rb', line 33
def put(local_path, remote_name)
@driver.put(local_path, remote_name)
end
|