Class: BFS::Bucket::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/bfs/bucket/abstract.rb

Direct Known Subclasses

FS, InMem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoding: Encoding.default_external, perm: nil, **_opts) ⇒ Abstract

Initializes a new bucket

Parameters:

  • opts (Hash)

    options



12
13
14
15
16
17
18
19
20
21
# File 'lib/bfs/bucket/abstract.rb', line 12

def initialize(encoding: Encoding.default_external, perm: nil, **_opts)
  @encoding = encoding

  case perm
  when Integer
    @perm = perm
  when String
    @perm = perm.to_i(8)
  end
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



6
7
8
# File 'lib/bfs/bucket/abstract.rb', line 6

def encoding
  @encoding
end

#permObject (readonly)

Returns the value of attribute perm.



6
7
8
# File 'lib/bfs/bucket/abstract.rb', line 6

def perm
  @perm
end

Instance Method Details

#closeObject

Closes the underlying connection



88
# File 'lib/bfs/bucket/abstract.rb', line 88

def close; end

#cp(src, dst, **opts) ⇒ Object

Copies src to dst

Parameters:

  • src (String)

    The source path.

  • dst (String)

    The destination path.



70
71
72
73
74
75
76
# File 'lib/bfs/bucket/abstract.rb', line 70

def cp(src, dst, **opts)
  open(src, **opts) do |r|
    create(dst, **opts) do |w|
      IO.copy_stream(r, w)
    end
  end
end

#create(_path, **_opts) ⇒ Object

Creates a new file and opens it for writing



34
35
36
# File 'lib/bfs/bucket/abstract.rb', line 34

def create(_path, **_opts)
  raise 'not implemented'
end

#info(_path, **_opts) ⇒ Object

Info returns the info for a single file



29
30
31
# File 'lib/bfs/bucket/abstract.rb', line 29

def info(_path, **_opts)
  raise 'not implemented'
end

#ls(_pattern = '**', **_opts) ⇒ Object

Lists the contents of a bucket using a glob pattern



24
25
26
# File 'lib/bfs/bucket/abstract.rb', line 24

def ls(_pattern = '**', **_opts)
  raise 'not implemented'
end

#mv(src, dst, **_opts) ⇒ Object

Moves src to dst

Parameters:

  • src (String)

    The source path.

  • dst (String)

    The destination path.



82
83
84
85
# File 'lib/bfs/bucket/abstract.rb', line 82

def mv(src, dst, **_opts)
  cp(src, dst)
  rm(src)
end

#open(_path, **_opts) ⇒ Object

Opens an existing file for reading May raise BFS::FileNotFound



40
41
42
# File 'lib/bfs/bucket/abstract.rb', line 40

def open(_path, **_opts)
  raise 'not implemented'
end

#read(path, **opts) ⇒ Object

Shortcut method to read the contents of a file into memory

Parameters:

  • path (String)

    The path to read from.

  • opts (Hash)

    Additional options, see #open.



53
54
55
# File 'lib/bfs/bucket/abstract.rb', line 53

def read(path, **opts)
  open(path, **opts, &:read)
end

#rm(_path, **_opts) ⇒ Object

Deletes a file.



45
46
47
# File 'lib/bfs/bucket/abstract.rb', line 45

def rm(_path, **_opts)
  raise 'not implemented'
end

#write(path, data, **opts) ⇒ Object

Shortcut method to write data to path

Parameters:

  • path (String)

    The path to write to.

  • data (String)

    The data to write.

  • opts (Hash)

    Additional options, see #create.



62
63
64
# File 'lib/bfs/bucket/abstract.rb', line 62

def write(path, data, **opts)
  create(path, **opts) {|f| f.write data }
end