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.
57
58
59
|
# File 'lib/folio/fileobject.rb', line 57
def path
@path
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.new(path) 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 FileNotFound.new(path)
end
end
|
Instance Method Details
#<=>(other) ⇒ Object
245
246
247
|
# File 'lib/folio/fileobject.rb', line 245
def <=>(other)
path <=> other.to_s
end
|
#==(other) ⇒ Object
59
60
61
62
63
|
# File 'lib/folio/fileobject.rb', line 59
def ==(other)
return false unless FileObject===other
@path == other.path
end
|
#atime ⇒ Object
179
|
# File 'lib/folio/fileobject.rb', line 179
def atime ; stat.atime ; end
|
#basename ⇒ Object
200
|
# File 'lib/folio/fileobject.rb', line 200
def basename ; ::File.basename(path) ; end
|
#blockdev? ⇒ Boolean
174
|
# File 'lib/folio/fileobject.rb', line 174
def blockdev? ; stat.blockdev? ; end
|
#chardev? ⇒ Boolean
175
|
# File 'lib/folio/fileobject.rb', line 175
def chardev? ; stat.chardev? ; end
|
#chmod(mode) ⇒ Object
123
124
125
|
# File 'lib/folio/fileobject.rb', line 123
def chmod(mode)
::File.chmod(mode, path)
end
|
#chown(user, group) ⇒ Object
127
128
129
|
# File 'lib/folio/fileobject.rb', line 127
def chown(user, group)
::File.chown(user, group, path)
end
|
#cp(dest) ⇒ Object
Copy file to destination path.
142
143
144
|
# File 'lib/folio/fileobject.rb', line 142
def cp(dest)
util.cp(path, dest)
end
|
#ctime ⇒ Object
180
|
# File 'lib/folio/fileobject.rb', line 180
def ctime ; stat.ctime ; end
|
#directory? ⇒ Boolean
173
|
# File 'lib/folio/fileobject.rb', line 173
def directory? ; stat.directory? ; end
|
#dirname ⇒ Object
201
|
# File 'lib/folio/fileobject.rb', line 201
def dirname ; ::File.dirname(path) ; end
|
#document? ⇒ Boolean
def file? ; stat.file? ; end
172
|
# File 'lib/folio/fileobject.rb', line 172
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.
67
68
69
|
# File 'lib/folio/fileobject.rb', line 67
def exist?
::FileTest.exist?(path)
end
|
#extname ⇒ Object
202
|
# File 'lib/folio/fileobject.rb', line 202
def extname ; ::File.extname(path) ; end
|
#fnmatch(pattern, flags = 0) ⇒ Object
Also known as:
fnmatch?
229
230
231
|
# File 'lib/folio/fileobject.rb', line 229
def fnmatch(pattern, flags=0)
::File.fnmatch(path, pattern, flags)
end
|
#grpowned? ⇒ Boolean
181
|
# File 'lib/folio/fileobject.rb', line 181
def grpowned? ; stat.grpowned? ; end
|
#identical? ⇒ Boolean
182
|
# File 'lib/folio/fileobject.rb', line 182
def identical? ; stat.identical? ; end
|
#inspect ⇒ Object
Inspect returns the path string relative to the current working directory.
240
|
# File 'lib/folio/fileobject.rb', line 240
def inspect; "#{relative}"; end
|
#install(dest, mode = nil) ⇒ Object
Install file to destination path.
147
148
149
|
# File 'lib/folio/fileobject.rb', line 147
def install(dest, mode=nil)
util.install(path, dest, mode)
end
|
#link(new) ⇒ Object
Also known as:
ln
81
82
83
|
# File 'lib/folio/fileobject.rb', line 81
def link(new)
::File.ln(path, new)
end
|
#link_force(new) ⇒ Object
Also known as:
ln_f
86
87
88
89
|
# File 'lib/folio/fileobject.rb', line 86
def link_force(new)
::File.remove(new)
link(new)
end
|
#mtime ⇒ Object
183
|
# File 'lib/folio/fileobject.rb', line 183
def mtime ; stat.mtime ; end
|
#owned? ⇒ Boolean
184
|
# File 'lib/folio/fileobject.rb', line 184
def owned? ; stat.owned? ; end
|
#parent ⇒ Object
Returns the parent directory object.
73
74
75
|
# File 'lib/folio/fileobject.rb', line 73
def parent
self.class[File.dirname(path)]
end
|
#pipe? ⇒ Boolean
177
|
# File 'lib/folio/fileobject.rb', line 177
def pipe? ; stat.pipe? ; end
|
#readable? ⇒ Boolean
185
|
# File 'lib/folio/fileobject.rb', line 185
def readable? ; stat.readable? ; end
|
#readable_real? ⇒ Boolean
186
|
# File 'lib/folio/fileobject.rb', line 186
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.
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/folio/fileobject.rb', line 210
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
103
104
105
106
|
# File 'lib/folio/fileobject.rb', line 103
def rename(dest)
::File.rename(path, dest)
@path = ::File.expand_path(dest)
end
|
#restat ⇒ Object
Also known as:
stat!
166
167
168
|
# File 'lib/folio/fileobject.rb', line 166
def restat
@stat = File.stat(path)
end
|
#setgid? ⇒ Boolean
187
|
# File 'lib/folio/fileobject.rb', line 187
def setgid? ; stat.setgid? ; end
|
#setuid? ⇒ Boolean
188
|
# File 'lib/folio/fileobject.rb', line 188
def setuid? ; stat.setuid? ; end
|
#size ⇒ Object
189
|
# File 'lib/folio/fileobject.rb', line 189
def size ; stat.size ; end
|
#size? ⇒ Boolean
190
|
# File 'lib/folio/fileobject.rb', line 190
def size? ; stat.size? ; end
|
#socket? ⇒ Boolean
176
|
# File 'lib/folio/fileobject.rb', line 176
def socket? ; stat.socket? ; end
|
#split ⇒ Object
TODO: I don’t like the name of this.
205
|
# File 'lib/folio/fileobject.rb', line 205
def split ; ::File.split(path) ; end
|
#stat ⇒ Object
161
162
163
|
# File 'lib/folio/fileobject.rb', line 161
def stat
@stat ||= File.stat(path)
end
|
#sticky? ⇒ Boolean
191
|
# File 'lib/folio/fileobject.rb', line 191
def sticky? ; stat.sticky? ; end
|
#symlink(new) ⇒ Object
Also known as:
ln_s
92
93
94
|
# File 'lib/folio/fileobject.rb', line 92
def symlink(new)
::File.symlink(path, new)
end
|
#symlink_force(new) ⇒ Object
Also known as:
ln_sf
97
98
99
100
|
# File 'lib/folio/fileobject.rb', line 97
def symlink_force(new)
::File.remove(new)
symlink(new)
end
|
#to_s ⇒ Object
243
|
# File 'lib/folio/fileobject.rb', line 243
def to_s ; path ; end
|
#touch ⇒ Object
152
153
154
|
# File 'lib/folio/fileobject.rb', line 152
def touch
util.touch(path)
end
|
#unlink ⇒ Object
Also known as:
delete, rm
how to handle –b/c it disappears?
110
111
112
|
# File 'lib/folio/fileobject.rb', line 110
def unlink
::File.delete(path)
end
|
#unlink_force ⇒ Object
Also known as:
delete_force, rm_f
116
117
118
119
|
# File 'lib/folio/fileobject.rb', line 116
def unlink_force
::File.remove(new)
unlink(path)
end
|
#utime(atime, mtime) ⇒ Object
131
132
133
|
# File 'lib/folio/fileobject.rb', line 131
def utime(atime, mtime)
::File.utime(atime, mtime, path)
end
|
#writable? ⇒ Boolean
192
|
# File 'lib/folio/fileobject.rb', line 192
def writable? ; stat.writable? ; end
|
#writable_real? ⇒ Boolean
193
|
# File 'lib/folio/fileobject.rb', line 193
def writable_real? ; stat.writable_real? ; end
|
#zero? ⇒ Boolean
194
|
# File 'lib/folio/fileobject.rb', line 194
def zero? ; stat.zero? ; end
|