Class: RPath::Adapters::Filesystem

Inherits:
RPath::Adapter show all
Defined in:
lib/rpath/adapters/filesystem.rb

Constant Summary collapse

ATTRIBUTES =

Attributes that may be passed as names to #attribute

%w{
blockdev?
chardev?
directory?
executable?
executable_real?
file?
grpowned?
owned?
pipe?
readable?
world_readable?
readable_real?
setgid?
setuid?
size
socket?
sticky?
symlink?
writable?
world_writable?
writable_real?
zero?
atime
birthtime
ctime
mtime
ftype
readlink
stat
lstat
dirname
extname
split }

Instance Method Summary collapse

Methods inherited from RPath::Adapter

#root

Instance Method Details

#adapts?(graph) ⇒ Boolean

Always false. The filesystem adapter must be specified in calls to #RPath.

Parameters:

  • graph (Object)

Returns:

  • (Boolean)


12
13
14
# File 'lib/rpath/adapters/filesystem.rb', line 12

def adapts?(graph)
  false
end

#adjacent(vertex) ⇒ Array<String>

Returns the expanded paths of the directory entries. An empty array if vertex is a file.

Parameters:

  • vertex (String)

    A filesystem path

Returns:

  • (Array<String>)

    Returns the expanded paths of the directory entries. An empty array if vertex is a file.



29
30
31
32
33
34
35
36
37
# 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) ⇒ Object?

Returns the value of the attribute; nil if the attribute is invalid.

Parameters:

  • vertex (String)

    A filesystem path

  • name (String, Symbol)

    An attribute in ATTRIBUTES

Returns:

  • (Object, nil)

    Returns the value of the attribute; nil if the attribute is invalid.



46
47
48
49
50
51
52
53
54
55
56
# 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) ⇒ String?

Returns the contents if vertex is a file; otherwise nil.

Parameters:

  • vertex (String)

    A filesystem path

Returns:

  • (String, nil)

    Returns the contents if vertex is a file; otherwise nil.



62
63
64
65
66
67
68
# 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) ⇒ String

Returns the basename

Parameters:

  • vertex (String)

    A filesystem path

Returns:

  • (String)

    Returns the basename



20
21
22
# File 'lib/rpath/adapters/filesystem.rb', line 20

def name(vertex)
  File.basename vertex
end