Class: RPath::Adapters::Filesystem
- Inherits:
-
RPath::Adapter
- Object
- RPath::Adapter
- RPath::Adapters::Filesystem
- 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
-
#adapts?(graph) ⇒ Boolean
Always false.
-
#adjacent(vertex) ⇒ Array<String>
Returns the expanded paths of the directory entries.
-
#attribute(vertex, name) ⇒ Object?
Returns the value of the attribute;
nil
if the attribute is invalid. -
#content(vertex) ⇒ String?
Returns the contents if
vertex
is a file; otherwisenil
. -
#name(vertex) ⇒ String
Returns the basename.
Methods inherited from RPath::Adapter
Instance Method Details
#adapts?(graph) ⇒ Boolean
Always false. The filesystem adapter must be specified in calls to #RPath.
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.
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.(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.
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.(vertex)).send(name) rescue SystemCallError nil end else nil end end |
#content(vertex) ⇒ String?
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.(vertex) rescue SystemCallError nil end end |
#name(vertex) ⇒ String
Returns the basename
20 21 22 |
# File 'lib/rpath/adapters/filesystem.rb', line 20 def name(vertex) File.basename vertex end |