Class: VirtualFS::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/virtualfs/backend.rb

Direct Known Subclasses

Github, Local

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Backend

Returns a new instance of Backend.



12
13
14
# File 'lib/virtualfs/backend.rb', line 12

def initialize(opts={})
  @cache = opts[:cache] || NullCache.new
end

Instance Method Details

#cache(&proc) ⇒ Object



16
17
18
19
20
# File 'lib/virtualfs/backend.rb', line 16

def cache(&proc)
  local_variable_values = eval('local_variables.map { |var| eval(var.to_s) }', proc.binding)
  key = caller[0] << local_variable_values.inspect
  @cache.cache(key, &proc)
end

#dotfolders_for(path) ⇒ Object



32
33
34
# File 'lib/virtualfs/backend.rb', line 32

def dotfolders_for(path)
  [VirtualFS::Dir.new(::File.join(path, '.'), self), VirtualFS::Dir.new(::File.join(path, '..'), self)]
end

#entries(path = nil) ⇒ Object

Raises:

  • (NotImplementedError)


36
37
38
39
# File 'lib/virtualfs/backend.rb', line 36

def entries(path=nil)
  # override this
  raise NotImplementedError
end

#glob(pattern, path = nil) ⇒ Object Also known as: []

Raises:

  • (NotImplementedError)


41
42
43
44
# File 'lib/virtualfs/backend.rb', line 41

def glob(pattern, path=nil)
  # override this
  raise NotImplementedError
end

#map_entries(paths, method = :to_s, &dir_criteria) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/virtualfs/backend.rb', line 22

def map_entries(paths, method=:to_s, &dir_criteria)
  paths.map do |path|
    if dir_criteria.call(path)
      VirtualFS::Dir.new(path.send(method), self)
    else
      VirtualFS::File.new(path.send(method), self)
    end
  end
end

#stream_for(path) ⇒ Object

Raises:

  • (NotImplementedError)


46
47
48
49
# File 'lib/virtualfs/backend.rb', line 46

def stream_for(path)
  # override this
  raise NotImplementedError
end