Class: RelPathname

Inherits:
Pathname
  • Object
show all
Defined in:
lib/relpathname.rb

Instance Method Summary collapse

Constructor Details

#initialize(p1) ⇒ RelPathname

Returns a new instance of RelPathname.



6
7
8
9
10
# File 'lib/relpathname.rb', line 6

def initialize p1
    @initial_pwd = Pathname.pwd

    super p1
end

Instance Method Details

#+(p1) ⇒ Object



26
27
28
# File 'lib/relpathname.rb', line 26

def + p1
    RelPathname.new to_pn + p1
end

#<=>(p1) ⇒ Object



30
31
32
# File 'lib/relpathname.rb', line 30

def <=> p1
    to_pn <=> p1
end

#==(p1) ⇒ Object



34
35
36
# File 'lib/relpathname.rb', line 34

def == p1
    to_pn == p1
end

#===(p1) ⇒ Object



38
39
40
# File 'lib/relpathname.rb', line 38

def === p1
    to_pn === p1
end

#absolute?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/relpathname.rb', line 42

def absolute?
    to_pn.absolute?
end

#basenameObject



46
47
48
# File 'lib/relpathname.rb', line 46

def basename
    RelPathname.new to_pn.basename
end

#children(*args) ⇒ Object



50
51
52
# File 'lib/relpathname.rb', line 50

def children *args
    to_pn.children(*args).map do |path| RelPathname.new path end
end

#cleanpath(*args) ⇒ Object



54
55
56
# File 'lib/relpathname.rb', line 54

def cleanpath *args
    RelPathname.new to_pn.cleanpath(*args)
end

#directory?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/relpathname.rb', line 58

def directory?
    to_pn.directory?
end

#dirnameObject



62
63
64
# File 'lib/relpathname.rb', line 62

def dirname
    RelPathname.new to_pn.dirname
end

#executable?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/relpathname.rb', line 66

def executable?
    to_pn.executable?
end

#executable_real?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/relpathname.rb', line 70

def executable_real?
    to_pn.executable_real?
end

#extnameObject



74
75
76
# File 'lib/relpathname.rb', line 74

def extname
    RelPathname.new to_pn.extname
end

#file?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/relpathname.rb', line 78

def file?
    to_pn.file?
end

#mkpathObject



82
83
84
# File 'lib/relpathname.rb', line 82

def mkpath
    RelPathname.new to_pn.mkpath
end

#mtimeObject



86
87
88
# File 'lib/relpathname.rb', line 86

def mtime
    to_pn.mtime
end

#parentObject



90
91
92
# File 'lib/relpathname.rb', line 90

def parent
    RelPathname.new to_pn.parent
end

#relative?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/relpathname.rb', line 94

def relative?
    to_pn.relative?
end

#symlink?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/relpathname.rb', line 98

def symlink?
    to_pn.symlink?
end

#to_pathObject



16
17
18
# File 'lib/relpathname.rb', line 16

def to_path
    (@initial_pwd + super).relative_path_from(Pathname.pwd).to_s
end

#to_pnObject



12
13
14
# File 'lib/relpathname.rb', line 12

def to_pn
    Pathname.new to_path
end

#to_sObject



21
22
23
24
# File 'lib/relpathname.rb', line 21

def to_s
    prefix = to_pn.each_filename.to_a[0] == '..' ? '' : './'
    prefix + to_path
end