Harbor Documentation

Attributes

  • root [RW] (Not documented)
  • options [RW] (Not documented)

Public Class Methods

new(path, options = {})

      # File lib/harbor/file_store/local.rb, line 7
 7:       def initialize(path, options = {})
 8:         path = "#{path}/" unless path =~ /.*\/$/
 9:         @root = Pathname(path)
10: 
11:         @options = options
12: 
13:         ::FileUtils.mkdir_p(path.to_s)
14:       end

Public Instance Methods

delete(path)

      # File lib/harbor/file_store/local.rb, line 32
32:       def delete(path)
33:         path = strip_leading_slash(path)
34:         ::FileUtils.rm(@root + path)
35:         Harbor::File.rmdir_p((@root + path).parent.to_s)
36:       end

exists?(path)

      # File lib/harbor/file_store/local.rb, line 38
38:       def exists?(path)
39:         path = strip_leading_slash(path)
40:         (@root + path).exist?
41:       end

get(path)

      # File lib/harbor/file_store/local.rb, line 16
16:       def get(path)
17:         path = strip_leading_slash(path)
18:         Harbor::FileStore::File.new(self, path)
19:       end

local?()

      # File lib/harbor/file_store/local.rb, line 54
54:       def local?
55:         true
56:       end

open(path, mode = "r", &block)

      # File lib/harbor/file_store/local.rb, line 43
43:       def open(path, mode = "r", &block)
44:         path = strip_leading_slash(path)
45:         ::FileUtils.mkdir_p((@root + path).parent.to_s) unless (@root + path).parent.exist?
46:         ::File.open(@root + path, mode, &block)
47:       end

put(path, absolute_path)

      # File lib/harbor/file_store/local.rb, line 21
21:       def put(path, absolute_path)
22:         raise ArgumentError.new("Harbor::FileStore::Local#put[absolute_path] should be a path but was an IO") if absolute_path.is_a?(IO)
23:         path = strip_leading_slash(path)
24:         file = Harbor::FileStore::File.new(self, path)
25: 
26:         ::FileUtils.mkdir_p((@root + path).parent.to_s) unless (@root + path).parent.exist?
27: 
28:         ::FileUtils::cp(absolute_path, file.absolute_path)
29:         file
30:       end

size(path)

      # File lib/harbor/file_store/local.rb, line 49
49:       def size(path)
50:         path = strip_leading_slash(path)
51:         ::File.size(@root + path)
52:       end

Private Instance Methods

__size__()

      # File lib/harbor/file_store/local.rb, line 60
60:       def __size__
61:         `du -sk #{Shellwords.escape(@root.to_s)} | awk '{ print $1; }'`.chomp.to_i * 1024
62:       end

strip_leading_slash(path)

      # File lib/harbor/file_store/local.rb, line 64
64:       def strip_leading_slash(path)
65:         path = path[1..path.size - 1] if path =~ /^\//
66:         path
67:       end