Class: RelPathname

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

Instance Method Summary collapse

Constructor Details

#initialize(p1) ⇒ RelPathname

Returns a new instance of RelPathname.



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

def initialize p1
    @initial_pwd = Pathname.pwd
    @origin_path = p1

    super p1
end

Instance Method Details

#+(p1) ⇒ Object



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

def + p1
    RelPathname.new to_pn + p1
end

#/(p) ⇒ Object



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

def / p
    RelPathname.new to_pn + p
end

#<=>(p1) ⇒ Object



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

def <=> p1
    to_pn <=> p1
end

#==(p1) ⇒ Object



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

def == p1
    to_pn == p1
end

#===(p1) ⇒ Object



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

def === p1
    to_pn === p1
end

#absolute?Boolean

Returns:

  • (Boolean)


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

def absolute?
    to_pn.absolute?
end

#basenameObject



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

def basename
    RelPathname.new to_pn.basename
end

#children(*args) ⇒ Object



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

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

#cleanpath(*args) ⇒ Object



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

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

#directory?Boolean

Returns:

  • (Boolean)


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

def directory?
    to_pn.directory?
end

#dirnameObject



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

def dirname
    RelPathname.new to_pn.dirname
end

#executable?Boolean

Returns:

  • (Boolean)


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

def executable?
    to_pn.executable?
end

#executable_real?Boolean

Returns:

  • (Boolean)


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

def executable_real?
    to_pn.executable_real?
end

#exist?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/relpathname.rb', line 121

def exist?
    Pathname.new(to_s).exist?
end

#extnameObject



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

def extname
    RelPathname.new to_pn.extname
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
    to_pn.file?
end

#mkpathObject



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

def mkpath
    RelPathname.new to_pn.mkpath
end

#mtimeObject



101
102
103
# File 'lib/relpathname.rb', line 101

def mtime
    to_pn.mtime
end

#parentObject



105
106
107
# File 'lib/relpathname.rb', line 105

def parent
    RelPathname.new to_pn.parent
end

#pwdObject



117
118
119
# File 'lib/relpathname.rb', line 117

def pwd
    RelPathname.new '.'
end

#relative?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/relpathname.rb', line 109

def relative?
    to_pn.relative?
end

#symlink?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/relpathname.rb', line 113

def symlink?
    to_pn.symlink?
end

#to_origin_sObject



28
29
30
# File 'lib/relpathname.rb', line 28

def to_origin_s
    @origin_path
end

#to_pathObject



24
25
26
# File 'lib/relpathname.rb', line 24

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

#to_pnObject



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

def to_pn
    Pathname.new to_path
end

#to_sObject



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

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