Class: Tms::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/tms/path.rb

Overview

cleaned up Pathname

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

Returns:

  • (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

Returns:

  • (Boolean)


61
62
63
# File 'lib/tms/path.rb', line 61

def exist?
  File.exist?(@path)
end

#file?Boolean

Returns:

  • (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

#ftypeObject



45
46
47
# File 'lib/tms/path.rb', line 45

def ftype
  File.ftype(@path)
end

#hashObject



17
18
19
# File 'lib/tms/path.rb', line 17

def hash
  @path.hash
end

#lstatObject



49
50
51
# File 'lib/tms/path.rb', line 49

def lstat
  File.lstat(@path)
end

#postfixObject



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

Returns:

  • (Boolean)


77
78
79
# File 'lib/tms/path.rb', line 77

def readable_real?
  File.readable_real?(@path)
end


41
42
43
# File 'lib/tms/path.rb', line 41

def readlink
  self.class.new(File.readlink(@path))
end

#sizeObject



53
54
55
# File 'lib/tms/path.rb', line 53

def size
  File.size(@path)
end

#size_if_real_fileObject



57
58
59
# File 'lib/tms/path.rb', line 57

def size_if_real_file
  file? && !symlink? ? File.size(@path) : 0
end

#symlink?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/tms/path.rb', line 73

def symlink?
  File.symlink?(@path)
end

#to_sObject Also known as: to_str, to_path



103
104
105
# File 'lib/tms/path.rb', line 103

def to_s
  @path.dup
end