class Path::Backend
Attributes
backend[RW]
Public Class Methods
delegate(mth)
click to toggle source
# File lib/rubypath/backend.rb, line 10 def delegate(mth) define_method mth do |*args| backend.send mth, *args end end
instance()
click to toggle source
# File lib/rubypath/backend.rb, line 6 def instance @instance ||= new end
mock(*args, &block)
click to toggle source
# File lib/rubypath/backend.rb, line 16 def mock(*args, &block) instance.mock(*args, &block) end
new()
click to toggle source
# File lib/rubypath/backend.rb, line 22 def initialize self.backend = Backend::Sys.new end
Public Instance Methods
mock(opts = {}, &block)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/rubypath/backend.rb, line 27 def mock(opts = {}, &block) if opts[:root] # Use real file system scoped to given directory (chroot like) if opts[:root] == :tmp ::Dir.mktmpdir('rubypath') do |path| use_backend Backend::Sys.new(path), &block end else use_backend Backend::Sys.new(opts[:root]), &block end else # Use mock FS use_backend Backend::Mock.new, &block end end
use_backend(be) { || ... }
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/rubypath/backend.rb, line 44 def use_backend(be) old_backend = backend self.backend = be yield backend.quit if backend.respond_to? :quit self.backend = old_backend end