class Dire::Node
Attributes
path[R]
root[R]
Public Class Methods
new(node, root, validate: true)
click to toggle source
# File lib/dire/node.rb, line 7 def initialize node, root, validate: true @path = str2abs node @root = plant root validate! if validate end
Public Instance Methods
get(path, validate: true)
click to toggle source
# File lib/dire/node.rb, line 14 def get path, validate: true path = expand path type = path.ftype rescue nil const = case type when 'directory' then Dir when 'file' then File when 'link' then Link else Other end const.new path, root, validate: validate end
parent()
click to toggle source
# File lib/dire/node.rb, line 29 def parent Dire::Dir.new absolute_path.join('..'), root rescue Dire::Error::InvalidPath nil end
to_s()
click to toggle source
# File lib/dire/node.rb, line 35 def to_s relative_path.to_s end
type()
click to toggle source
# File lib/dire/node.rb, line 39 def type path.ftype rescue 'other' end
Private Instance Methods
plant(root)
click to toggle source
# File lib/dire/node.rb, line 45 def plant root root = str2abs root unless root.directory? raise Dire::Error::InvalidRoot, 'Not a dir' end root end
str2abs(path)
click to toggle source
# File lib/dire/node.rb, line 55 def str2abs path Pathname.new(path).expand_path end