Class: Harbor::FileStore::Local
Instance Attribute Summary collapse
Instance Method Summary
collapse
[], exists?, file_stores, get, register
Constructor Details
#initialize(path, options = {}) ⇒ Local
Returns a new instance of Local.
7
8
9
10
11
12
13
14
|
# File 'lib/harbor/file_store/local.rb', line 7
def initialize(path, options = {})
path = "#{path}/" unless path =~ /.*\/$/
@root = Pathname(path)
@options = options
::FileUtils.mkdir_p(path.to_s)
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5
6
7
|
# File 'lib/harbor/file_store/local.rb', line 5
def options
@options
end
|
#root ⇒ Object
Returns the value of attribute root.
5
6
7
|
# File 'lib/harbor/file_store/local.rb', line 5
def root
@root
end
|
Instance Method Details
#delete(path) ⇒ Object
32
33
34
35
36
|
# File 'lib/harbor/file_store/local.rb', line 32
def delete(path)
path = strip_leading_slash(path)
::FileUtils.rm(@root + path)
Harbor::File.rmdir_p((@root + path).parent.to_s)
end
|
#exists?(path) ⇒ Boolean
38
39
40
41
|
# File 'lib/harbor/file_store/local.rb', line 38
def exists?(path)
path = strip_leading_slash(path)
(@root + path).exist?
end
|
#get(path) ⇒ Object
16
17
18
19
|
# File 'lib/harbor/file_store/local.rb', line 16
def get(path)
path = strip_leading_slash(path)
Harbor::FileStore::File.new(self, path)
end
|
#local? ⇒ Boolean
54
55
56
|
# File 'lib/harbor/file_store/local.rb', line 54
def local?
true
end
|
#open(path, mode = "r", &block) ⇒ Object
43
44
45
46
47
|
# File 'lib/harbor/file_store/local.rb', line 43
def open(path, mode = "r", &block)
path = strip_leading_slash(path)
::FileUtils.mkdir_p((@root + path).parent.to_s) unless (@root + path).parent.exist?
::File.open(@root + path, mode, &block)
end
|
#put(path, absolute_path) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/harbor/file_store/local.rb', line 21
def put(path, absolute_path)
raise ArgumentError.new("Harbor::FileStore::Local#put[absolute_path] should be a path but was an IO") if absolute_path.is_a?(IO)
path = strip_leading_slash(path)
file = Harbor::FileStore::File.new(self, path)
::FileUtils.mkdir_p((@root + path).parent.to_s) unless (@root + path).parent.exist?
::FileUtils::cp(absolute_path, file.absolute_path)
file
end
|
#size(path) ⇒ Object
49
50
51
52
|
# File 'lib/harbor/file_store/local.rb', line 49
def size(path)
path = strip_leading_slash(path)
::File.size(@root + path)
end
|