Module: BFS

Defined in:
lib/bfs.rb,
lib/bfs/blob.rb,
lib/bfs/bucket.rb,
lib/bfs/errors.rb,
lib/bfs/helpers.rb,
lib/bfs/bucket/fs.rb,
lib/bfs/bucket/in_mem.rb,
lib/bfs/bucket/abstract.rb

Defined Under Namespace

Modules: Bucket Classes: Blob, FileInfo, FileNotFound, TempWriter

Class Method Summary collapse

Class Method Details

.defer(obj, method) ⇒ Object



68
69
70
71
# File 'lib/bfs.rb', line 68

def self.defer(obj, method)
  owner = Process.pid
  ObjectSpace.define_finalizer(obj, ->(*) { obj.send(method) if Process.pid == owner })
end

.norm_mode(mode) ⇒ Object



63
64
65
66
# File 'lib/bfs.rb', line 63

def self.norm_mode(mode)
  mode = mode.to_i(8) if mode.is_a?(String)
  mode & 0o000777
end

.norm_path(path) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/bfs.rb', line 55

def self.norm_path(path)
  path = path.to_s.dup
  path.gsub!(File::SEPARATOR, '/')
  path.sub!(%r{^/+}, '')
  path.sub!(%r{/+$}, '')
  path
end

.register(*schemes, &resolver) ⇒ Object



36
37
38
39
40
41
# File 'lib/bfs.rb', line 36

def self.register(*schemes, &resolver)
  @registry ||= {}
  schemes.each do |scheme|
    @registry[scheme] = resolver
  end
end

.resolve(url, &block) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bfs.rb', line 43

def self.resolve(url, &block)
  url = url.is_a?(::URI) ? url.dup : URI.parse(url)
  rsl = @registry[url.scheme]
  raise ArgumentError, "Unable to resolve #{url}, scheme #{url.scheme} is not registered" unless rsl

  opts = {}
  CGI.parse(url.query.to_s).each do |key, values|
    opts[key.to_sym] = values.first
  end
  rsl.call(url, opts, block)
end