Class: Tms::Path
- Inherits:
-
Object
- Object
- Tms::Path
- Defined in:
- lib/tms/path.rb
Overview
cleaned up Pathname
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #/(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #===, #eql?)
- #basename(*args) ⇒ Object
- #children(with_directory = true) ⇒ Object
- #directory? ⇒ Boolean
- #dirname(*args) ⇒ Object
- #exist? ⇒ Boolean
- #file? ⇒ Boolean
- #find(&block) ⇒ Object
- #ftype ⇒ Object
- #hash ⇒ Object
-
#initialize(*parts) ⇒ Path
constructor
A new instance of Path.
- #lstat ⇒ Object
- #postfix ⇒ Object
- #readable_real? ⇒ Boolean
- #readlink ⇒ Object
- #size ⇒ Object
- #size_if_real_file ⇒ Object
- #symlink? ⇒ Boolean
- #to_s ⇒ Object (also: #to_str, #to_path)
Constructor Details
#initialize(*parts) ⇒ Path
Returns a new instance of Path.
9 10 11 |
# File 'lib/tms/path.rb', line 9 def initialize(*parts) @path = File.join(*parts) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/tms/path.rb', line 8 def path @path end |
Instance Method Details
#/(other) ⇒ Object
13 14 15 |
# File 'lib/tms/path.rb', line 13 def /(other) self.class.new(@path, other) end |
#<=>(other) ⇒ Object
28 29 30 31 |
# File 'lib/tms/path.rb', line 28 def <=>(other) return nil unless Path === other @path <=> other.to_s end |
#==(other) ⇒ Object Also known as: ===, eql?
21 22 23 24 |
# File 'lib/tms/path.rb', line 21 def ==(other) return false unless Path === other other.to_s == @path end |
#basename(*args) ⇒ Object
33 34 35 |
# File 'lib/tms/path.rb', line 33 def basename(*args) self.class.new(File.basename(@path, *args)) end |
#children(with_directory = true) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tms/path.rb', line 81 def children(with_directory = true) with_directory = false if @path == '.' result = [] Dir.foreach(@path) do |e| next if e == '.' || e == '..' if with_directory result << self.class.new(File.join(@path, e)) else result << self.class.new(e) end end result end |
#directory? ⇒ Boolean
69 70 71 |
# File 'lib/tms/path.rb', line 69 def directory? File.directory?(@path) end |
#dirname(*args) ⇒ Object
37 38 39 |
# File 'lib/tms/path.rb', line 37 def dirname(*args) self.class.new(File.dirname(@path)) end |
#exist? ⇒ Boolean
61 62 63 |
# File 'lib/tms/path.rb', line 61 def exist? File.exist?(@path) end |
#file? ⇒ Boolean
65 66 67 |
# File 'lib/tms/path.rb', line 65 def file? File.file?(@path) end |
#find(&block) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/tms/path.rb', line 95 def find(&block) if @path == '.' Find.find(@path){ |f| yield self.class.new(f.sub(/^.\//, '')) } else Find.find(@path){ |f| yield self.class.new(f) } end end |
#ftype ⇒ Object
45 46 47 |
# File 'lib/tms/path.rb', line 45 def ftype File.ftype(@path) end |
#hash ⇒ Object
17 18 19 |
# File 'lib/tms/path.rb', line 17 def hash @path.hash end |
#lstat ⇒ Object
49 50 51 |
# File 'lib/tms/path.rb', line 49 def lstat File.lstat(@path) end |
#postfix ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/tms/path.rb', line 109 def postfix case when symlink? '@' when directory? '/' else '' end end |
#readable_real? ⇒ Boolean
77 78 79 |
# File 'lib/tms/path.rb', line 77 def readable_real? File.readable_real?(@path) end |
#readlink ⇒ Object
41 42 43 |
# File 'lib/tms/path.rb', line 41 def readlink self.class.new(File.readlink(@path)) end |
#size ⇒ Object
53 54 55 |
# File 'lib/tms/path.rb', line 53 def size File.size(@path) end |
#size_if_real_file ⇒ Object
57 58 59 |
# File 'lib/tms/path.rb', line 57 def size_if_real_file file? && !symlink? ? File.size(@path) : 0 end |
#symlink? ⇒ Boolean
73 74 75 |
# File 'lib/tms/path.rb', line 73 def symlink? File.symlink?(@path) end |
#to_s ⇒ Object Also known as: to_str, to_path
103 104 105 |
# File 'lib/tms/path.rb', line 103 def to_s @path.dup end |