class RPath::Adapters::Filesystem

Constants

ATTRIBUTES

Attributes that may be passed as names to {#attribute}

Public Instance Methods

adapts?(graph) click to toggle source

Always false. The filesystem adapter must be specified in calls to {#RPath}. @param [Object] graph @return [Boolean]

# File lib/rpath/adapters/filesystem.rb, line 12
def adapts?(graph)
  false
end
adjacent(vertex) click to toggle source

@param [String] vertex

A filesystem path

@return [Array<String>]

Returns the expanded paths of the directory entries. An empty array
if +vertex+ is a file.
# File lib/rpath/adapters/filesystem.rb, line 29
def adjacent(vertex)
  begin
    entries = Dir.entries(File.expand_path(vertex))
  rescue SystemCallError
    return []
  end

  entries.collect { |entry| File.join(vertex, entry) }
end
attribute(vertex, name) click to toggle source

@param [String] vertex

A filesystem path

@param [String, Symbol] name

An attribute in {ATTRIBUTES}

@return [Object, nil]

Returns the value of the attribute; +nil+ if the attribute is
invalid.
# File lib/rpath/adapters/filesystem.rb, line 46
def attribute(vertex, name)
  if ATTRIBUTES.include?(name.to_s)
    begin
      Pathname(File.expand_path(vertex)).send(name)
    rescue SystemCallError
      nil
    end
  else
    nil
  end
end
content(vertex) click to toggle source

@param [String] vertex

A filesystem path

@return [String, nil]

Returns the contents if +vertex+ is a file; otherwise +nil+.
# File lib/rpath/adapters/filesystem.rb, line 62
def content(vertex)
  begin
    File.read File.expand_path(vertex)
  rescue SystemCallError
    nil
  end
end
name(vertex) click to toggle source

@param [String] vertex

A filesystem path

@return [String]

Returns the basename
# File lib/rpath/adapters/filesystem.rb, line 20
def name(vertex)
  File.basename vertex
end