Class: Dire::Node
- Inherits:
-
Object
- Object
- Dire::Node
- Includes:
- Module::Check, Module::Path, Module::Validity
- Defined in:
- lib/dire/node.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #get(path, validate: true) ⇒ Object
-
#initialize(node, root, validate: true) ⇒ Node
constructor
A new instance of Node.
- #parent ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(node, root, validate: true) ⇒ Node
9 10 11 12 13 14 |
# File 'lib/dire/node.rb', line 9 def initialize node, root, validate: true @path = str2abs node @root = plant root validate! if validate end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/dire/node.rb', line 7 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/dire/node.rb', line 7 def root @root end |
Instance Method Details
#get(path, validate: true) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dire/node.rb', line 16 def get path, validate: true path = 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 ⇒ Object
31 32 33 34 35 |
# File 'lib/dire/node.rb', line 31 def parent Dire::Dir.new absolute_path.join('..'), root rescue Dire::Error::InvalidPath nil end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/dire/node.rb', line 37 def to_s relative_path.to_s end |
#type ⇒ Object
41 42 43 |
# File 'lib/dire/node.rb', line 41 def type path.ftype rescue 'other' end |