Class: Folio::FileObject
- Inherits:
-
Object
show all
- Defined in:
- lib/folio/fileobject.rb
Overview
File Object
Base class for all folio objects.
Constant Summary
collapse
- Separator =
::File::Separator
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
55
56
57
|
# File 'lib/folio/fileobject.rb', line 55
def path
@path
end
|
#relpath ⇒ Object
Returns the value of attribute relpath.
56
57
58
|
# File 'lib/folio/fileobject.rb', line 56
def relpath
@relpath
end
|
Class Method Details
.[](*path) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/folio/fileobject.rb', line 20
def self.[](*path)
path = ::File.join(*path)
raise FileNotFound unless ::File.exist?(path)
case ::File.ftype(path)
when 'file'
Document.new(path)
when 'directory'
Directory.new(path)
when 'link'
Link.new(path)
when 'characterSpecial'
CharacterDevice.new(path)
when 'blockSpecial'
BlockDevice.new(path)
when 'socket'
raise TypeError
when 'fifo'
raise TypeError
else
raise TypeError
end
end
|
Instance Method Details
#<=>(other) ⇒ Object
233
234
235
|
# File 'lib/folio/fileobject.rb', line 233
def <=>(other)
path <=> other.to_s
end
|
#==(other) ⇒ Object
237
238
239
|
# File 'lib/folio/fileobject.rb', line 237
def ==(other)
path == other.path
end
|
#atime ⇒ Object
167
|
# File 'lib/folio/fileobject.rb', line 167
def atime ; stat.atime ; end
|
#basename ⇒ Object
188
|
# File 'lib/folio/fileobject.rb', line 188
def basename ; ::File.basename(path) ; end
|
#blockdev? ⇒ Boolean
162
|
# File 'lib/folio/fileobject.rb', line 162
def blockdev? ; stat.blockdev? ; end
|
#chardev? ⇒ Boolean
163
|
# File 'lib/folio/fileobject.rb', line 163
def chardev? ; stat.chardev? ; end
|
#chmod(mode) ⇒ Object
112
113
114
|
# File 'lib/folio/fileobject.rb', line 112
def chmod(mode)
::File.chmod(mode, path)
end
|
#chown(user, group) ⇒ Object
116
117
118
|
# File 'lib/folio/fileobject.rb', line 116
def chown(user, group)
::File.chown(user, group, path)
end
|
#cp(dest) ⇒ Object
Copy file to destination path.
131
132
133
|
# File 'lib/folio/fileobject.rb', line 131
def cp(dest)
util.cp(path, dest)
end
|
#ctime ⇒ Object
168
|
# File 'lib/folio/fileobject.rb', line 168
def ctime ; stat.ctime ; end
|
#directory? ⇒ Boolean
161
|
# File 'lib/folio/fileobject.rb', line 161
def directory? ; stat.directory? ; end
|
#dirname ⇒ Object
189
|
# File 'lib/folio/fileobject.rb', line 189
def dirname ; ::File.dirname(path) ; end
|
#document? ⇒ Boolean
def file? ; stat.file? ; end
160
|
# File 'lib/folio/fileobject.rb', line 160
def document? ; stat.file? ; end
|
#exist? ⇒ Boolean
Also known as:
exists?
This will alwasy be true, EXCEPT when #rm, #delete or #unlink have been used.
60
61
62
|
# File 'lib/folio/fileobject.rb', line 60
def exist?
::FileTest.exist?(path)
end
|
#extname ⇒ Object
190
|
# File 'lib/folio/fileobject.rb', line 190
def extname ; ::File.extname(path) ; end
|
#fnmatch(pattern, flags = 0) ⇒ Object
Also known as:
fnmatch?
217
218
219
|
# File 'lib/folio/fileobject.rb', line 217
def fnmatch(pattern, flags=0)
::File.fnmatch(path, pattern, flags)
end
|
#grpowned? ⇒ Boolean
169
|
# File 'lib/folio/fileobject.rb', line 169
def grpowned? ; stat.grpowned? ; end
|
#identical? ⇒ Boolean
170
|
# File 'lib/folio/fileobject.rb', line 170
def identical? ; stat.identical? ; end
|
#inspect ⇒ Object
Inspect returns the path string relative to the current working directory.
228
|
# File 'lib/folio/fileobject.rb', line 228
def inspect; "#{relative}"; end
|
#install(dest, mode = nil) ⇒ Object
Install file to destination path.
136
137
138
|
# File 'lib/folio/fileobject.rb', line 136
def install(dest, mode=nil)
util.install(path, dest, mode)
end
|
#link(new) ⇒ Object
Also known as:
ln
69
70
71
|
# File 'lib/folio/fileobject.rb', line 69
def link(new)
::File.ln(path, new)
end
|
#link_force(new) ⇒ Object
Also known as:
ln_f
74
75
76
77
|
# File 'lib/folio/fileobject.rb', line 74
def link_force(new)
::File.remove(new)
link(new)
end
|
#mtime ⇒ Object
171
|
# File 'lib/folio/fileobject.rb', line 171
def mtime ; stat.mtime ; end
|
#owned? ⇒ Boolean
172
|
# File 'lib/folio/fileobject.rb', line 172
def owned? ; stat.owned? ; end
|
#pipe? ⇒ Boolean
165
|
# File 'lib/folio/fileobject.rb', line 165
def pipe? ; stat.pipe? ; end
|
#readable? ⇒ Boolean
173
|
# File 'lib/folio/fileobject.rb', line 173
def readable? ; stat.readable? ; end
|
#readable_real? ⇒ Boolean
174
|
# File 'lib/folio/fileobject.rb', line 174
def readable_real? ; stat.readable_real ; end
|
#relative ⇒ Object
Gives path relative to current working directory. If current is below path one step then it uses ‘..’, further below and it returns the full path.
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/folio/fileobject.rb', line 198
def relative
pwd = Dir.pwd
pth = path
if pth.index(pwd) == 0
r = pth[pwd.size+1..-1]
r = '.' unless r
return r
else
pwd = File.dirname(pwd)
if pth.index(pwd) == 0
r = pth[pwd.size+1..-1]
return '..' unless r
return File.join('..', r)
else
pth
end
end
end
|
#rename(dest) ⇒ Object
Also known as:
mv
91
92
93
94
95
|
# File 'lib/folio/fileobject.rb', line 91
def rename(dest)
::File.rename(path, dest)
@relpath = dest
@path = ::File.expand_path(dest)
end
|
#restat ⇒ Object
Also known as:
stat!
154
155
156
|
# File 'lib/folio/fileobject.rb', line 154
def restat
@stat = File.stat(path)
end
|
#setgid? ⇒ Boolean
175
|
# File 'lib/folio/fileobject.rb', line 175
def setgid? ; stat.setgid? ; end
|
#setuid? ⇒ Boolean
176
|
# File 'lib/folio/fileobject.rb', line 176
def setuid? ; stat.setuid? ; end
|
#size ⇒ Object
177
|
# File 'lib/folio/fileobject.rb', line 177
def size ; stat.size ; end
|
#size? ⇒ Boolean
178
|
# File 'lib/folio/fileobject.rb', line 178
def size? ; stat.size? ; end
|
#socket? ⇒ Boolean
164
|
# File 'lib/folio/fileobject.rb', line 164
def socket? ; stat.socket? ; end
|
#split ⇒ Object
TODO: I don’t like the name of this.
193
|
# File 'lib/folio/fileobject.rb', line 193
def split ; ::File.split(path) ; end
|
#stat ⇒ Object
149
150
151
|
# File 'lib/folio/fileobject.rb', line 149
def stat
@stat ||= File.stat(path)
end
|
#sticky? ⇒ Boolean
179
|
# File 'lib/folio/fileobject.rb', line 179
def sticky? ; stat.sticky? ; end
|
#symlink(new) ⇒ Object
Also known as:
ln_s
80
81
82
|
# File 'lib/folio/fileobject.rb', line 80
def symlink(new)
::File.symlink(path, new)
end
|
#symlink_force(new) ⇒ Object
Also known as:
ln_sf
85
86
87
88
|
# File 'lib/folio/fileobject.rb', line 85
def symlink_force(new)
::File.remove(new)
symlink(new)
end
|
#to_s ⇒ Object
231
|
# File 'lib/folio/fileobject.rb', line 231
def to_s ; path ; end
|
#touch ⇒ Object
140
141
142
|
# File 'lib/folio/fileobject.rb', line 140
def touch
util.touch(path)
end
|
#unlink ⇒ Object
Also known as:
delete, rm
how to handle –b/c it disappears?
99
100
101
|
# File 'lib/folio/fileobject.rb', line 99
def unlink
::File.delete(path)
end
|
#unlink_force ⇒ Object
Also known as:
delete_force, rm_f
105
106
107
108
|
# File 'lib/folio/fileobject.rb', line 105
def unlink_force
::File.remove(new)
unlink(path)
end
|
#utime(atime, mtime) ⇒ Object
120
121
122
|
# File 'lib/folio/fileobject.rb', line 120
def utime(atime, mtime)
::File.utime(atime, mtime, path)
end
|
#writable? ⇒ Boolean
180
|
# File 'lib/folio/fileobject.rb', line 180
def writable? ; stat.writable? ; end
|
#writable_real? ⇒ Boolean
181
|
# File 'lib/folio/fileobject.rb', line 181
def writable_real? ; stat.writable_real? ; end
|
#zero? ⇒ Boolean
182
|
# File 'lib/folio/fileobject.rb', line 182
def zero? ; stat.zero? ; end
|