Class: Ronin::Path
Overview
The Path class extends Pathname
to allow representing directory
traversal paths.
Instance Attribute Summary collapse
-
#separator ⇒ Object
The separator to join paths together with.
Class Method Summary collapse
-
.root ⇒ Path
The root path.
-
.up(n, separator = File::SEPARATOR) ⇒ Path
Creates a new path object for upward directory traversal.
Instance Method Summary collapse
-
#initialize(path, separator = File::SEPARATOR) ⇒ Path
constructor
Initializes a new Path.
-
#join(*names) ⇒ Path
(also: #/)
Joins directory names together with the path, but does not resolve the resulting path.
Constructor Details
#initialize(path, separator = File::SEPARATOR) ⇒ Path
Initializes a new Path.
43 44 45 46 47 |
# File 'lib/ronin/path.rb', line 43 def initialize(path,separator=File::SEPARATOR) @separator = separator super(path) end |
Instance Attribute Details
#separator ⇒ Object
The separator to join paths together with
32 33 34 |
# File 'lib/ronin/path.rb', line 32 def separator @separator end |
Class Method Details
.root ⇒ Path
The root path.
55 56 57 |
# File 'lib/ronin/path.rb', line 55 def Path.root Path.new('/') end |
.up(n, separator = File::SEPARATOR) ⇒ Path
Creates a new path object for upward directory traversal.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ronin/path.rb', line 83 def self.up(n,separator=File::SEPARATOR) case n when Integer if n == 0 separator elsif n > 0 path = new('..',separator) path.join(*(['..'] * (n-1))) else raise(ArgumentError,"negative argument") end when Enumerable n.map { |i| up(i) } else raise(ArgumentError,"The first argument of Path.up must be either an Integer or Enumerable") end end |
Instance Method Details
#join(*names) ⇒ Path Also known as: /
Joins directory names together with the path, but does not resolve the resulting path.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ronin/path.rb', line 115 def join(*names) joined_path = if root? then '' else self.to_s end names.each do |name| name = name.to_s joined_path << @separator unless name.start_with?(@separator) joined_path << name unless name == @separator end return self.class.new(joined_path,@separator) end |