folio 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +675 -0
- data/MANIFEST +234 -0
- data/METADATA +8 -0
- data/NEWS +9 -0
- data/README +69 -0
- data/demo/sample1/foo/foo.txt +1 -0
- data/demo/sample1/tryme.rb +14 -0
- data/doc/rdoc/classes/Folio/BlockDevice.html +117 -0
- data/doc/rdoc/classes/Folio/CharacterDevice.html +117 -0
- data/doc/rdoc/classes/Folio/Device.html +119 -0
- data/doc/rdoc/classes/Folio/Directory.html +420 -0
- data/doc/rdoc/classes/Folio/Document.html +261 -0
- data/doc/rdoc/classes/Folio/FileNotFound.html +92 -0
- data/doc/rdoc/classes/Folio/FileObject.html +1200 -0
- data/doc/rdoc/classes/Folio/Link.html +238 -0
- data/doc/rdoc/classes/Folio/Pipe.html +131 -0
- data/doc/rdoc/classes/Folio/Prompt.html +796 -0
- data/doc/rdoc/classes/Folio/Socket.html +115 -0
- data/doc/rdoc/classes/Folio.html +148 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/COPYING.html +992 -0
- data/doc/rdoc/files/METADATA.html +101 -0
- data/doc/rdoc/files/NEWS.html +102 -0
- data/doc/rdoc/files/README.html +171 -0
- data/doc/rdoc/files/lib/folio/device_rb.html +96 -0
- data/doc/rdoc/files/lib/folio/directory_rb.html +96 -0
- data/doc/rdoc/files/lib/folio/document_rb.html +96 -0
- data/doc/rdoc/files/lib/folio/errors_rb.html +92 -0
- data/doc/rdoc/files/lib/folio/fileobject_rb.html +92 -0
- data/doc/rdoc/files/lib/folio/link_rb.html +96 -0
- data/doc/rdoc/files/lib/folio/pipe_rb.html +96 -0
- data/doc/rdoc/files/lib/folio/prompt_rb.html +92 -0
- data/doc/rdoc/files/lib/folio/socket_rb.html +96 -0
- data/doc/rdoc/files/lib/folio_rb.html +105 -0
- data/doc/rdoc/fr_class_index.html +58 -0
- data/doc/rdoc/fr_file_index.html +60 -0
- data/doc/rdoc/fr_method_index.html +185 -0
- data/doc/rdoc/index.html +26 -0
- data/doc/rdoc/rdoc-style.css +175 -0
- data/doc/ri/Folio/BlockDevice/blockdev%3f-i.yaml +10 -0
- data/doc/ri/Folio/BlockDevice/cdesc-BlockDevice.yaml +18 -0
- data/doc/ri/Folio/CharacterDevice/cdesc-CharacterDevice.yaml +18 -0
- data/doc/ri/Folio/CharacterDevice/chardev%3f-i.yaml +10 -0
- data/doc/ri/Folio/Device/cdesc-Device.yaml +18 -0
- data/doc/ri/Folio/Device/new-c.yaml +10 -0
- data/doc/ri/Folio/Directory/%2b-i.yaml +12 -0
- data/doc/ri/Folio/Directory/%2f-i.yaml +13 -0
- data/doc/ri/Folio/Directory/cd-i.yaml +12 -0
- data/doc/ri/Folio/Directory/cdesc-Directory.yaml +49 -0
- data/doc/ri/Folio/Directory/chdir-i.yaml +11 -0
- data/doc/ri/Folio/Directory/chmod_r-i.yaml +10 -0
- data/doc/ri/Folio/Directory/chown_r-i.yaml +12 -0
- data/doc/ri/Folio/Directory/chroot-i.yaml +10 -0
- data/doc/ri/Folio/Directory/cp_r-i.yaml +12 -0
- data/doc/ri/Folio/Directory/delete-i.yaml +12 -0
- data/doc/ri/Folio/Directory/directory%3f-i.yaml +10 -0
- data/doc/ri/Folio/Directory/entries-i.yaml +12 -0
- data/doc/ri/Folio/Directory/foreach-i.yaml +10 -0
- data/doc/ri/Folio/Directory/new-c.yaml +10 -0
- data/doc/ri/Folio/Directory/paths-i.yaml +12 -0
- data/doc/ri/Folio/Directory/rm_r-i.yaml +10 -0
- data/doc/ri/Folio/Directory/rm_rf-i.yaml +10 -0
- data/doc/ri/Folio/Directory/rmdir-i.yaml +13 -0
- data/doc/ri/Folio/Directory/unlink-i.yaml +12 -0
- data/doc/ri/Folio/Document/cdesc-Document.yaml +34 -0
- data/doc/ri/Folio/Document/delete-i.yaml +10 -0
- data/doc/ri/Folio/Document/executable%3f-i.yaml +10 -0
- data/doc/ri/Folio/Document/executable_real%3f-i.yaml +10 -0
- data/doc/ri/Folio/Document/file%3f-i.yaml +10 -0
- data/doc/ri/Folio/Document/intialize-i.yaml +10 -0
- data/doc/ri/Folio/Document/open-i.yaml +10 -0
- data/doc/ri/Folio/Document/read-i.yaml +10 -0
- data/doc/ri/Folio/Document/readlines-i.yaml +10 -0
- data/doc/ri/Folio/Document/truncate-i.yaml +10 -0
- data/doc/ri/Folio/Document/unlink-i.yaml +12 -0
- data/doc/ri/Folio/FileNotFound/cdesc-FileNotFound.yaml +15 -0
- data/doc/ri/Folio/FileObject/%3c%3d%3e-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/%3d%3d-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/%5b%5d-c.yaml +12 -0
- data/doc/ri/Folio/FileObject/atime-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/basename-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/blockdev%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/cdesc-FileObject.yaml +154 -0
- data/doc/ri/Folio/FileObject/chardev%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/chmod-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/chown-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/cp-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/ctime-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/delete-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/delete_force-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/directory%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/dirname-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/exist%3f-i.yaml +13 -0
- data/doc/ri/Folio/FileObject/exists%3f-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/extname-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/file%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/fnmatch%3f-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/fnmatch-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/grpowned%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/identical%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/inspect-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/install-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/link-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/link_force-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/ln-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/ln_f-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/ln_s-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/ln_sf-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/mtime-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/mv-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/new-c.yaml +10 -0
- data/doc/ri/Folio/FileObject/owned%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/pipe%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/readable%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/readable_real%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/relative-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/rename-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/restat-i.yaml +13 -0
- data/doc/ri/Folio/FileObject/rm-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/rm_f-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/setgid%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/setuid%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/size%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/size-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/socket%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/split-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/stat%21-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/stat-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/sticky%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/symlink-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/symlink_force-i.yaml +11 -0
- data/doc/ri/Folio/FileObject/to_s-i.yaml +12 -0
- data/doc/ri/Folio/FileObject/touch-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/unlink-i.yaml +15 -0
- data/doc/ri/Folio/FileObject/unlink_force-i.yaml +13 -0
- data/doc/ri/Folio/FileObject/util-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/utime-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/writable%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/writable_real%3f-i.yaml +10 -0
- data/doc/ri/Folio/FileObject/zero%3f-i.yaml +10 -0
- data/doc/ri/Folio/Link/cdesc-Link.yaml +29 -0
- data/doc/ri/Folio/Link/lchmod-i.yaml +10 -0
- data/doc/ri/Folio/Link/lchown-i.yaml +10 -0
- data/doc/ri/Folio/Link/link%3f-i.yaml +10 -0
- data/doc/ri/Folio/Link/lstat-i.yaml +10 -0
- data/doc/ri/Folio/Link/method_missing-i.yaml +11 -0
- data/doc/ri/Folio/Link/new-c.yaml +10 -0
- data/doc/ri/Folio/Link/readlink-i.yaml +10 -0
- data/doc/ri/Folio/Link/symlink%3f-i.yaml +10 -0
- data/doc/ri/Folio/Pipe/cdesc-Pipe.yaml +17 -0
- data/doc/ri/Folio/Pipe/new-c.yaml +10 -0
- data/doc/ri/Folio/Pipe/pipe%3f-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/%2b-i.yaml +13 -0
- data/doc/ri/Folio/Prompt/%2f-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/%5b%5d-c.yaml +10 -0
- data/doc/ri/Folio/Prompt/cd-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/cdesc-Prompt.yaml +89 -0
- data/doc/ri/Folio/Prompt/chmod-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/chmod_r-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/chown-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/chown_r-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/cp-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/cp_r-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/directories-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/entries-i.yaml +13 -0
- data/doc/ri/Folio/Prompt/file-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/files-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/fileutils-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/glob-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/install-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/ln-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/ln_s-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/ln_sf-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/localize-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/ls-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/mkdir-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/mkdir_p-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/mode-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/mv-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/new-c.yaml +11 -0
- data/doc/ri/Folio/Prompt/paths-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/pwd-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/rm-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/rm_r-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/rm_rf-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/rmdir-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/to_s-i.yaml +10 -0
- data/doc/ri/Folio/Prompt/touch-i.yaml +12 -0
- data/doc/ri/Folio/Socket/cdesc-Socket.yaml +16 -0
- data/doc/ri/Folio/Socket/new-c.yaml +10 -0
- data/doc/ri/Folio/cdesc-Folio.yaml +15 -0
- data/doc/ri/created.rid +1 -0
- data/lib/folio/device.rb +29 -0
- data/lib/folio/directory.rb +83 -0
- data/lib/folio/document.rb +66 -0
- data/lib/folio/errors.rb +7 -0
- data/lib/folio/fileobject.rb +242 -0
- data/lib/folio/link.rb +49 -0
- data/lib/folio/pipe.rb +16 -0
- data/lib/folio/prompt.rb +239 -0
- data/lib/folio/socket.rb +14 -0
- data/lib/folio.rb +79 -0
- data/test/fixture/bar.txt +0 -0
- data/test/fixture/foo.txt +0 -0
- data/test/test_folio.rb +28 -0
- data/test/test_helper.rb +7 -0
- metadata +300 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
--- !ruby/object:RI::MethodDescription
|
|
2
|
+
aliases: []
|
|
3
|
+
|
|
4
|
+
block_params:
|
|
5
|
+
comment:
|
|
6
|
+
- !ruby/struct:SM::Flow::P
|
|
7
|
+
body: alias_method :chown_R, :chown_r
|
|
8
|
+
full_name: Folio::Prompt#touch
|
|
9
|
+
is_singleton: false
|
|
10
|
+
name: touch
|
|
11
|
+
params: (list, options)
|
|
12
|
+
visibility: public
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
--- !ruby/object:RI::ClassDescription
|
|
2
|
+
attributes: []
|
|
3
|
+
|
|
4
|
+
class_methods:
|
|
5
|
+
- !ruby/object:RI::MethodSummary
|
|
6
|
+
name: new
|
|
7
|
+
comment:
|
|
8
|
+
constants: []
|
|
9
|
+
|
|
10
|
+
full_name: Folio::Socket
|
|
11
|
+
includes: []
|
|
12
|
+
|
|
13
|
+
instance_methods: []
|
|
14
|
+
|
|
15
|
+
name: Socket
|
|
16
|
+
superclass: FileObject
|
data/doc/ri/created.rid
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Thu, 21 Aug 2008 15:20:49 -0400
|
data/lib/folio/device.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'folio/fileobject'
|
|
2
|
+
|
|
3
|
+
module Folio
|
|
4
|
+
|
|
5
|
+
# Device base class
|
|
6
|
+
class Device < FileObject
|
|
7
|
+
|
|
8
|
+
def initialize(path)
|
|
9
|
+
raise 'Devices not yet supported.'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Character device
|
|
15
|
+
class CharacterDevice < Device
|
|
16
|
+
|
|
17
|
+
def chardev? ; true ; end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Block device
|
|
22
|
+
class BlockDevice < Device
|
|
23
|
+
|
|
24
|
+
def blockdev? ; true ; end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'folio/fileobject'
|
|
2
|
+
|
|
3
|
+
module Folio
|
|
4
|
+
|
|
5
|
+
class Directory < FileObject
|
|
6
|
+
|
|
7
|
+
def initialize(path=nil)
|
|
8
|
+
super(path || Dir.pwd)
|
|
9
|
+
raise FileNotFound unless ::File.directory?(@path)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def directory? ; true ; end
|
|
13
|
+
|
|
14
|
+
# We have to use FileUtils here b/c of some obscure
|
|
15
|
+
# secutiry issue.
|
|
16
|
+
|
|
17
|
+
# Copy recursively.
|
|
18
|
+
def cp_r(dest)
|
|
19
|
+
util.cp_r(path, dest)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def rmdir
|
|
23
|
+
util.rmdir(path)
|
|
24
|
+
end
|
|
25
|
+
alias_method :unlink, :rmdir
|
|
26
|
+
alias_method :delete, :rmdir
|
|
27
|
+
undef_method :rm
|
|
28
|
+
|
|
29
|
+
def rm_r
|
|
30
|
+
util.rm_r(path)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def rm_rf(list)
|
|
34
|
+
util.rm_rf(path)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def chmod_r(mode)
|
|
38
|
+
util.chmod_r(mode, path)
|
|
39
|
+
end
|
|
40
|
+
#alias_method :chmod_R, :chmod_r
|
|
41
|
+
|
|
42
|
+
def chown_r(user, group)
|
|
43
|
+
util.chown_r(user, group, path)
|
|
44
|
+
end
|
|
45
|
+
#alias_method :chown_R, :chown_r
|
|
46
|
+
|
|
47
|
+
#--
|
|
48
|
+
# ::Dir
|
|
49
|
+
#++
|
|
50
|
+
|
|
51
|
+
def chdir(&block)
|
|
52
|
+
::Dir.chdir(path, &block)
|
|
53
|
+
end
|
|
54
|
+
alias_method :cd, :chdir
|
|
55
|
+
|
|
56
|
+
def chroot(&block)
|
|
57
|
+
::Dir.chroot(path, &block)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Directory entries. This returns a list of file names.
|
|
61
|
+
def entries
|
|
62
|
+
::Dir.entries(path)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def foreach(&block)
|
|
66
|
+
::Dir.foreach(path, &block)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# TODO: use enumerator (?)
|
|
70
|
+
def paths
|
|
71
|
+
(::Dir.entries(path) - ['.', '..']).collect{ |f| FileObject[path, f] }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Join paths.
|
|
75
|
+
def /(fname)
|
|
76
|
+
FileObject[path, fname]
|
|
77
|
+
end
|
|
78
|
+
alias_method :+, :/
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'folio/fileobject'
|
|
2
|
+
|
|
3
|
+
module Folio
|
|
4
|
+
|
|
5
|
+
class Document < FileObject
|
|
6
|
+
|
|
7
|
+
def intialize(path)
|
|
8
|
+
super
|
|
9
|
+
raise FileNotFound unless ::File.file?(@path)
|
|
10
|
+
raise FileNotFound if ::File.symlink?(@path)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#--
|
|
14
|
+
# Polymorphism
|
|
15
|
+
#++
|
|
16
|
+
|
|
17
|
+
def file? ; true ; end
|
|
18
|
+
|
|
19
|
+
#--
|
|
20
|
+
# FileTest::
|
|
21
|
+
#++
|
|
22
|
+
|
|
23
|
+
def executable? ; ::FileTest.executable?(path) ; end
|
|
24
|
+
def executable_real? ; ::FileTest.executable_real?(path) ; end
|
|
25
|
+
|
|
26
|
+
#--
|
|
27
|
+
# File::
|
|
28
|
+
#++
|
|
29
|
+
|
|
30
|
+
def read ; ::File.read(path) ; end
|
|
31
|
+
|
|
32
|
+
def readlines ; ::File.readlines(path) ; end
|
|
33
|
+
|
|
34
|
+
# TODO: how to handle unkinking (b/c file no longer exists)
|
|
35
|
+
def unlink ; ::File.unlink(path) ; end
|
|
36
|
+
def delete ; ::File.delete(path) ; end
|
|
37
|
+
|
|
38
|
+
#--
|
|
39
|
+
# File.open
|
|
40
|
+
#++
|
|
41
|
+
|
|
42
|
+
def open(mode, &block)
|
|
43
|
+
::File.open(path, mode, &block)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def truncate(size)
|
|
47
|
+
::File.open(path, 'w'){|f| f.truncate(size)}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#--
|
|
51
|
+
# Can we handle other modes besides read this way?
|
|
52
|
+
#++
|
|
53
|
+
|
|
54
|
+
#flock(mode) ; _file.flock(mode) ; end
|
|
55
|
+
|
|
56
|
+
#def method_missing(s, *a, &b)
|
|
57
|
+
# _file.send(s, *a, &b)
|
|
58
|
+
#end
|
|
59
|
+
|
|
60
|
+
#private
|
|
61
|
+
|
|
62
|
+
#def _file ; @_file ||= ::File.new(path) ; end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
data/lib/folio/errors.rb
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
|
|
2
|
+
module Folio
|
|
3
|
+
|
|
4
|
+
# = File Object
|
|
5
|
+
#
|
|
6
|
+
# Base class for all folio objects.
|
|
7
|
+
#
|
|
8
|
+
class FileObject
|
|
9
|
+
|
|
10
|
+
Separator = ::File::Separator
|
|
11
|
+
|
|
12
|
+
# Factory method.
|
|
13
|
+
def self.[](*path)
|
|
14
|
+
path = ::File.join(*path)
|
|
15
|
+
|
|
16
|
+
raise FileNotFound unless ::File.exist?(path)
|
|
17
|
+
|
|
18
|
+
case ::File.ftype(path)
|
|
19
|
+
when 'file'
|
|
20
|
+
Document.new(path)
|
|
21
|
+
when 'directory'
|
|
22
|
+
Directory.new(path)
|
|
23
|
+
when 'link'
|
|
24
|
+
Link.new(path)
|
|
25
|
+
when 'characterSpecial'
|
|
26
|
+
CharacterDevice.new(path)
|
|
27
|
+
when 'blockSpecial'
|
|
28
|
+
BlockDevice.new(path)
|
|
29
|
+
when 'socket'
|
|
30
|
+
raise TypeError # Socket.new(path) ?
|
|
31
|
+
when 'fifo'
|
|
32
|
+
raise TypeError # Pipe?
|
|
33
|
+
else # 'unknown'
|
|
34
|
+
raise TypeError
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def initialize(path)
|
|
41
|
+
raise FileNotFound unless ::File.exist?(path)
|
|
42
|
+
@relpath = path
|
|
43
|
+
@path = ::File.expand_path(path)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
public
|
|
47
|
+
|
|
48
|
+
attr :path
|
|
49
|
+
attr :relpath
|
|
50
|
+
|
|
51
|
+
# This will alwasy be true, EXCEPT when
|
|
52
|
+
# #rm, #delete or #unlink have been used.
|
|
53
|
+
def exist?
|
|
54
|
+
::FileTest.exist?(path)
|
|
55
|
+
end
|
|
56
|
+
alias_method :exists?, :exist?
|
|
57
|
+
|
|
58
|
+
#--
|
|
59
|
+
# File Manipulation
|
|
60
|
+
#++
|
|
61
|
+
|
|
62
|
+
def link(new)
|
|
63
|
+
::File.ln(path, new)
|
|
64
|
+
end
|
|
65
|
+
alias_method :ln, :link
|
|
66
|
+
|
|
67
|
+
def link_force(new)
|
|
68
|
+
::File.remove(new)
|
|
69
|
+
link(new)
|
|
70
|
+
end
|
|
71
|
+
alias_method :ln_f, :link_force
|
|
72
|
+
|
|
73
|
+
def symlink(new)
|
|
74
|
+
::File.symlink(path, new)
|
|
75
|
+
end
|
|
76
|
+
alias_method :ln_s, :symlink
|
|
77
|
+
|
|
78
|
+
def symlink_force(new)
|
|
79
|
+
::File.remove(new)
|
|
80
|
+
symlink(new)
|
|
81
|
+
end
|
|
82
|
+
alias_method :ln_sf, :symlink_force
|
|
83
|
+
|
|
84
|
+
def rename(dest)
|
|
85
|
+
::File.rename(path, dest)
|
|
86
|
+
@relpath = dest
|
|
87
|
+
@path = ::File.expand_path(dest)
|
|
88
|
+
end
|
|
89
|
+
alias_method :mv, :rename
|
|
90
|
+
|
|
91
|
+
# how to handle --b/c it disappears?
|
|
92
|
+
def unlink
|
|
93
|
+
::File.delete(path)
|
|
94
|
+
end
|
|
95
|
+
alias_method :delete, :unlink
|
|
96
|
+
alias_method :rm, :unlink
|
|
97
|
+
|
|
98
|
+
def unlink_force
|
|
99
|
+
::File.remove(new)
|
|
100
|
+
unlink(path)
|
|
101
|
+
end
|
|
102
|
+
alias_method :delete_force, :unlink_force
|
|
103
|
+
alias_method :rm_f, :unlink_force
|
|
104
|
+
|
|
105
|
+
def chmod(mode)
|
|
106
|
+
::File.chmod(mode, path)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def chown(user, group)
|
|
110
|
+
::File.chown(user, group, path)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def utime(atime, mtime)
|
|
114
|
+
::File.utime(atime, mtime, path)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Wherever possible we have tried to avoid using
|
|
118
|
+
# FileUtils. Hoever there are a few methods that
|
|
119
|
+
# require it's use becuase of the complications
|
|
120
|
+
# in their implementation. Evenutlly we might port
|
|
121
|
+
# these methods.
|
|
122
|
+
|
|
123
|
+
# Copy file to destination path.
|
|
124
|
+
def cp(dest)
|
|
125
|
+
util.cp(path, dest)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Install file to destination path.
|
|
129
|
+
def install(dest, mode=nil)
|
|
130
|
+
util.install(path, dest, mode)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def touch
|
|
134
|
+
util.touch(path)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Status methods. These methods all access a cached
|
|
138
|
+
# ::File::Stat object. You can use #stat! to refresh
|
|
139
|
+
# the status cache.
|
|
140
|
+
|
|
141
|
+
# Get stat and cache it.
|
|
142
|
+
def stat
|
|
143
|
+
@stat ||= File.stat(path)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Refresh status cache.
|
|
147
|
+
def restat
|
|
148
|
+
@stat = File.stat(path)
|
|
149
|
+
end
|
|
150
|
+
alias_method :stat!, :restat
|
|
151
|
+
|
|
152
|
+
def file? ; stat.file? ; end
|
|
153
|
+
def directory? ; stat.directory? ; end
|
|
154
|
+
def blockdev? ; stat.blockdev? ; end
|
|
155
|
+
def chardev? ; stat.chardev? ; end
|
|
156
|
+
def socket? ; stat.socket? ; end
|
|
157
|
+
def pipe? ; stat.pipe? ; end
|
|
158
|
+
|
|
159
|
+
def atime ; stat.atime ; end
|
|
160
|
+
def ctime ; stat.ctime ; end
|
|
161
|
+
def grpowned? ; stat.grpowned? ; end
|
|
162
|
+
def identical? ; stat.identical? ; end
|
|
163
|
+
def mtime ; stat.mtime ; end
|
|
164
|
+
def owned? ; stat.owned? ; end
|
|
165
|
+
def readable? ; stat.readable? ; end
|
|
166
|
+
def readable_real? ; stat.readable_real ; end
|
|
167
|
+
def setgid? ; stat.setgid? ; end
|
|
168
|
+
def setuid? ; stat.setuid? ; end
|
|
169
|
+
def size ; stat.size ; end
|
|
170
|
+
def size? ; stat.size? ; end
|
|
171
|
+
def sticky? ; stat.sticky? ; end
|
|
172
|
+
def writable? ; stat.writable? ; end
|
|
173
|
+
def writable_real? ; stat.writable_real? ; end
|
|
174
|
+
def zero? ; stat.zero? ; end
|
|
175
|
+
|
|
176
|
+
#--
|
|
177
|
+
# Pathname Methods
|
|
178
|
+
#++
|
|
179
|
+
|
|
180
|
+
def basename ; ::File.basename(path) ; end
|
|
181
|
+
def dirname ; ::File.dirname(path) ; end
|
|
182
|
+
def extname ; ::File.extname(path) ; end
|
|
183
|
+
|
|
184
|
+
# TODO: I don't like the name of this.
|
|
185
|
+
def split ; ::File.split(path) ; end
|
|
186
|
+
|
|
187
|
+
# Gives path relative to current working directory.
|
|
188
|
+
# If current is below path one step then it uses '..',
|
|
189
|
+
# further below and it returns the full path.
|
|
190
|
+
def relative
|
|
191
|
+
pwd = Dir.pwd
|
|
192
|
+
pth = path
|
|
193
|
+
if pth.index(pwd) == 0
|
|
194
|
+
r = pth[pwd.size+1..-1]
|
|
195
|
+
r = '.' unless r
|
|
196
|
+
return r
|
|
197
|
+
else
|
|
198
|
+
pwd = File.dirname(pwd)
|
|
199
|
+
if pth.index(pwd) == 0
|
|
200
|
+
r = pth[pwd.size+1..-1]
|
|
201
|
+
return '..' unless r
|
|
202
|
+
return File.join('..', r)
|
|
203
|
+
else
|
|
204
|
+
pth
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def fnmatch(pattern, flags=0)
|
|
210
|
+
::File.fnmatch(path, pattern, flags)
|
|
211
|
+
end
|
|
212
|
+
alias_method :fnmatch?, :fnmatch
|
|
213
|
+
|
|
214
|
+
#--
|
|
215
|
+
# Standard Object Methods
|
|
216
|
+
#++
|
|
217
|
+
|
|
218
|
+
# Inspect returns the path string relative to
|
|
219
|
+
# the current working directory.
|
|
220
|
+
def inspect; "#{relative}"; end
|
|
221
|
+
|
|
222
|
+
# Returns the path string.
|
|
223
|
+
def to_s ; path ; end
|
|
224
|
+
|
|
225
|
+
def <=>(other)
|
|
226
|
+
path <=> other.to_s
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def ==(other)
|
|
230
|
+
path == other.path
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
private
|
|
234
|
+
|
|
235
|
+
def util
|
|
236
|
+
::FileUtils
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
end
|
|
242
|
+
|
data/lib/folio/link.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'folio/fileobject'
|
|
2
|
+
|
|
3
|
+
module Folio
|
|
4
|
+
|
|
5
|
+
class Link < FileObject
|
|
6
|
+
|
|
7
|
+
def initialize(path)
|
|
8
|
+
super
|
|
9
|
+
raise FileNotFound unless ::File.symlink?(@path)
|
|
10
|
+
|
|
11
|
+
@folio = Folio.new(::File.readlink(path))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#--
|
|
15
|
+
# Am I write to think any file object can be linked?
|
|
16
|
+
#++
|
|
17
|
+
|
|
18
|
+
def symlink?
|
|
19
|
+
::File.symlink(path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def link?
|
|
23
|
+
::File.link?(path)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def readlink
|
|
27
|
+
::File.readlink(path)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def lchmod(mode)
|
|
31
|
+
::File.lchmod(mode, path)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def lchown(own, grp)
|
|
35
|
+
::File.lchown(own, grp, path)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def lstat
|
|
39
|
+
::File.lstat(path)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#
|
|
43
|
+
def method_missing(s, *a, &b)
|
|
44
|
+
@folio.send(s, *a, &b)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|