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.



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

def adapts?(graph)
  false
end

#adjacent(vertex) ⇒ Array<String>



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?



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?



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



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

def name(vertex)
  File.basename vertex
end