class Path::Backend::Mock::Dir

Public Class Methods

new(backend, name, opts = {}) click to toggle source
Calls superclass method Path::Backend::Mock::Node::new
# File lib/rubypath/backend/mock.rb, line 303
def initialize(backend, name, opts = {})
  super
  self.mode = 0o777 - backend.umask
end

Public Instance Methods

add(node) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rubypath/backend/mock.rb, line 342
def children
  @children ||= []
end
lookup(path) click to toggle source
# File lib/rubypath/backend/mock.rb, line 308
def lookup(path) # rubocop:disable MethodLength
  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