Class: Path::Backend::Mock::Dir
- Inherits:
-
Node
- Object
- Node
- Path::Backend::Mock::Dir
show all
- Defined in:
- lib/rubypath/backend/mock.rb
Instance Attribute Summary
Attributes inherited from Node
#atime, #mode, #mtime, #name, #parent, #sys
Internal Virtual File System
collapse
Methods inherited from Node
#added, #path
Constructor Details
#initialize(backend, name, opts = {}) ⇒ Dir
303
304
305
306
|
# File 'lib/rubypath/backend/mock.rb', line 303
def initialize(backend, name, opts = {})
super
self.mode = 0o777 - backend.umask
end
|
Instance Method Details
#add(node) ⇒ Object
325
326
327
328
329
330
331
332
|
# File 'lib/rubypath/backend/mock.rb', line 325
def add(node)
if children.any? {|c| c.name == node.name }
raise ArgumentError.new "Node #{path}/#{node.name} already exists."
end
children << node
node.added self
end
|
#all ⇒ Object
334
335
336
337
338
339
340
|
# File 'lib/rubypath/backend/mock.rb', line 334
def all
children.reduce([]) do |memo, child|
memo << child
memo += child.all if child.is_a?(Dir)
memo
end
end
|
#children ⇒ Object
342
343
344
|
# File 'lib/rubypath/backend/mock.rb', line 342
def children
@children ||= []
end
|
#lookup(path) ⇒ Object
rubocop:disable MethodLength
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/rubypath/backend/mock.rb', line 308
def lookup(path)
name, rest = path.to_s.split('/', 2).map(&:to_s)
if name.nil?
if rest.nil?
self
else
lookup rest
end
else
child = children.find {|c| c.name == name }
if child
rest.nil? ? child : child.lookup(rest)
end
end
end
|