Class: Path::Backend
- Inherits:
-
Object
- Object
- Path::Backend
- Defined in:
- lib/rubypath/backend.rb,
lib/rubypath/backend/sys.rb,
lib/rubypath/backend/mock.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#backend ⇒ Object
Returns the value of attribute backend.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Backend
constructor
A new instance of Backend.
-
#mock(opts = {}, &block) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#use_backend(be) ⇒ Object
rubocop:enable Metrics/MethodLength.
Constructor Details
#initialize ⇒ Backend
Returns a new instance of Backend.
22 23 24 |
# File 'lib/rubypath/backend.rb', line 22 def initialize self.backend = Backend::Sys.new end |
Instance Attribute Details
#backend ⇒ Object
Returns the value of attribute backend.
21 22 23 |
# File 'lib/rubypath/backend.rb', line 21 def backend @backend end |
Class Method Details
.delegate(mth) ⇒ Object
10 11 12 13 14 |
# File 'lib/rubypath/backend.rb', line 10 def delegate(mth) define_method mth do |*args| backend.send mth, *args end end |
.instance ⇒ Object
6 7 8 |
# File 'lib/rubypath/backend.rb', line 6 def instance @instance ||= new end |
.mock(*args, &block) ⇒ Object
16 17 18 |
# File 'lib/rubypath/backend.rb', line 16 def mock(*args, &block) instance.mock(*args, &block) end |
Instance Method Details
#mock(opts = {}, &block) ⇒ Object
rubocop:disable Metrics/MethodLength
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
rubocop:enable Metrics/MethodLength
44 45 46 47 48 49 50 |
# 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 |