folio 0.1.0 → 0.2.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/CHANGES +2 -0
- data/MANIFEST +20 -5
- data/METADATA +3 -2
- data/README +5 -0
- data/doc/rdoc/classes/Enumerator.html +92 -0
- data/doc/rdoc/classes/Folio.html +12 -2
- data/doc/rdoc/classes/Folio/BlockDevice.html +4 -4
- data/doc/rdoc/classes/Folio/CharacterDevice.html +4 -4
- data/doc/rdoc/classes/Folio/Directory.html +169 -41
- data/doc/rdoc/classes/Folio/Document.html +130 -51
- data/doc/rdoc/classes/Folio/FileObject.html +318 -313
- data/doc/rdoc/classes/Folio/Pipe.html +8 -8
- data/doc/rdoc/classes/Folio/Prompt.html +261 -218
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +92 -0
- data/doc/rdoc/files/METADATA.html +7 -6
- data/doc/rdoc/files/README.html +1 -1
- data/doc/rdoc/files/lib/folio/directory_rb.html +1 -1
- data/doc/rdoc/files/lib/folio/document_rb.html +1 -1
- data/doc/rdoc/files/lib/folio/fileobject_rb.html +6 -1
- data/doc/rdoc/files/lib/folio/prompt_rb.html +1 -1
- data/doc/rdoc/files/lib/folio_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +1 -0
- data/doc/rdoc/fr_file_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +126 -116
- data/doc/ri/Enumerator/cdesc-Enumerator.yaml +15 -0
- data/doc/ri/Folio/Directory/%2f-i.yaml +1 -1
- data/doc/ri/Folio/Directory/cdesc-Directory.yaml +10 -2
- data/doc/ri/Folio/Directory/chdir-i.yaml +3 -1
- data/doc/ri/Folio/Directory/chmod_r-i.yaml +2 -0
- data/doc/ri/Folio/Directory/chown_r-i.yaml +1 -1
- data/doc/ri/Folio/Directory/chroot-i.yaml +2 -0
- data/doc/ri/Folio/Directory/cp_r-i.yaml +1 -1
- data/doc/ri/Folio/Directory/directories-i.yaml +12 -0
- data/doc/ri/Folio/Directory/directory_entries-i.yaml +12 -0
- data/doc/ri/Folio/Directory/document_entries-i.yaml +12 -0
- data/doc/ri/Folio/Directory/documents-i.yaml +12 -0
- data/doc/ri/Folio/Directory/entries-i.yaml +1 -1
- data/doc/ri/Folio/Directory/files-i.yaml +12 -0
- data/doc/ri/Folio/Directory/foreach-i.yaml +2 -0
- data/doc/ri/Folio/Directory/rm_r-i.yaml +2 -0
- data/doc/ri/Folio/Directory/rm_rf-i.yaml +2 -0
- data/doc/ri/Folio/Directory/rmdir-i.yaml +2 -0
- data/doc/ri/Folio/Document/%3c%3c-i.yaml +12 -0
- data/doc/ri/Folio/{Prompt/paths-i.yaml → Document/%3c-i.yaml} +4 -4
- data/doc/ri/Folio/Document/append-i.yaml +13 -0
- data/doc/ri/Folio/Document/cdesc-Document.yaml +10 -2
- data/doc/ri/Folio/{Directory/paths-i.yaml → Document/document%3f-i.yaml} +3 -3
- data/doc/ri/Folio/Document/write-i.yaml +13 -0
- data/doc/ri/Folio/FileObject/cdesc-FileObject.yaml +2 -2
- data/doc/ri/Folio/FileObject/{file%3f-i.yaml → document%3f-i.yaml} +4 -2
- data/doc/ri/Folio/Prompt/{pwd-i.yaml → %5b%5d-i.yaml} +5 -3
- data/doc/ri/Folio/Prompt/cdesc-Prompt.yaml +11 -5
- data/doc/ri/Folio/Prompt/directories-i.yaml +1 -1
- data/doc/ri/Folio/Prompt/directory_entries-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/document_entries-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/documents-i.yaml +12 -0
- data/doc/ri/Folio/Prompt/entries-i.yaml +1 -1
- data/doc/ri/Folio/Prompt/file-i.yaml +4 -3
- data/doc/ri/Folio/Prompt/files-i.yaml +1 -1
- data/doc/ri/Folio/Prompt/fileutils-i.yaml +2 -0
- data/doc/ri/Folio/Prompt/mode-i.yaml +1 -1
- data/doc/ri/created.rid +1 -1
- data/lib/folio.rb +7 -50
- data/lib/folio/directory.rb +55 -10
- data/lib/folio/document.rb +14 -1
- data/lib/folio/fileobject.rb +9 -1
- data/lib/folio/prompt.rb +65 -25
- metadata +25 -9
- data/doc/ri/Folio/Document/file%3f-i.yaml +0 -10
@@ -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: Returns Enumerator of directories.
|
8
|
+
full_name: Folio::Prompt#documents
|
9
|
+
is_singleton: false
|
10
|
+
name: documents
|
11
|
+
params: ()
|
12
|
+
visibility: public
|
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:RI::MethodDescription
|
2
|
-
aliases:
|
3
|
-
|
2
|
+
aliases:
|
3
|
+
- !ruby/object:RI::AliasName
|
4
|
+
name: "[]"
|
4
5
|
block_params:
|
5
6
|
comment:
|
6
7
|
- !ruby/struct:SM::Flow::P
|
7
|
-
body: Get the FileObject.
|
8
|
+
body: Get the FileObject for the given file name.
|
8
9
|
full_name: Folio::Prompt#file
|
9
10
|
is_singleton: false
|
10
11
|
name: file
|
@@ -4,7 +4,7 @@ aliases: []
|
|
4
4
|
block_params:
|
5
5
|
comment:
|
6
6
|
- !ruby/struct:SM::Flow::P
|
7
|
-
body:
|
7
|
+
body: Opertaton mode. This can be :noop, :verbose or :dryrun. The later is the same as the first two combined.
|
8
8
|
full_name: Folio::Prompt#mode
|
9
9
|
is_singleton: false
|
10
10
|
name: mode
|
data/doc/ri/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Sat, 30 Aug 2008 23:40:59 -0400
|
data/lib/folio.rb
CHANGED
@@ -15,6 +15,13 @@ require 'folio/pipe'
|
|
15
15
|
|
16
16
|
# = Folio
|
17
17
|
#
|
18
|
+
# In folio the term `file` means a file object. That is to say any
|
19
|
+
# type of file system resource: document, directory, device, etc.
|
20
|
+
# We use the term `document` instead to mean "regular files".
|
21
|
+
# This terminolgy was chosen for two reasons. Namely, (1) a
|
22
|
+
# differentiation in terms was required; and (2) a file in the
|
23
|
+
# everyday sense is something in which one puts papars (eg. documents).
|
24
|
+
#
|
18
25
|
module Folio
|
19
26
|
|
20
27
|
def self.file(*path)
|
@@ -27,53 +34,3 @@ module Folio
|
|
27
34
|
|
28
35
|
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#pwd()
|
39
|
-
=begin
|
40
|
-
if ::File.blockdev?(path)
|
41
|
-
Device.new(path)
|
42
|
-
elsif chardev?(path)
|
43
|
-
Device.new(path)
|
44
|
-
elsif pipe?(path)
|
45
|
-
Device.new(path)
|
46
|
-
elsif ::File.socket?(path)
|
47
|
-
Socket.new(path)
|
48
|
-
elsif ::File.directory?(path)
|
49
|
-
Directory.new(path)
|
50
|
-
else
|
51
|
-
Document.new(path)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
=end
|
55
|
-
|
56
|
-
# delegate ?
|
57
|
-
=begin
|
58
|
-
def initialize(path)
|
59
|
-
@path = path = ::File.join(*path)
|
60
|
-
|
61
|
-
raise FileNotFound unless ::File.exist?(path)
|
62
|
-
|
63
|
-
if ::File.blockdev?(path) or chardev?(path)
|
64
|
-
@delegate = Device.new(path)
|
65
|
-
elsif ::File.link?(path)
|
66
|
-
@delegate = Link.new(path)
|
67
|
-
elsif ::File.directory?(path)
|
68
|
-
@delegate = Directory.new(path)
|
69
|
-
else
|
70
|
-
@delegate = Document.new(path)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def delete
|
75
|
-
@delegate.delete
|
76
|
-
@delegate = nil
|
77
|
-
end
|
78
|
-
=end
|
79
|
-
|
data/lib/folio/directory.rb
CHANGED
@@ -12,13 +12,14 @@ module Folio
|
|
12
12
|
def directory? ; true ; end
|
13
13
|
|
14
14
|
# We have to use FileUtils here b/c of some obscure
|
15
|
-
# secutiry
|
15
|
+
# secutiry issues.
|
16
16
|
|
17
|
-
# Copy recursively.
|
17
|
+
# Copy this directory recursively to destination.
|
18
18
|
def cp_r(dest)
|
19
19
|
util.cp_r(path, dest)
|
20
20
|
end
|
21
21
|
|
22
|
+
# Remove this directory. Fails if not empty.
|
22
23
|
def rmdir
|
23
24
|
util.rmdir(path)
|
24
25
|
end
|
@@ -26,19 +27,35 @@ module Folio
|
|
26
27
|
alias_method :delete, :rmdir
|
27
28
|
undef_method :rm
|
28
29
|
|
30
|
+
# Remove this directory and all it's content.
|
29
31
|
def rm_r
|
30
32
|
util.rm_r(path)
|
31
33
|
end
|
32
34
|
|
35
|
+
# Remove this directory and all it's content forcefully.
|
33
36
|
def rm_rf(list)
|
34
37
|
util.rm_rf(path)
|
35
38
|
end
|
36
39
|
|
40
|
+
# Change the mode of this directory.
|
41
|
+
#def chmod(mode)
|
42
|
+
# util.chmod(mode, path)
|
43
|
+
#end
|
44
|
+
|
45
|
+
# Change the owner of this directory.
|
46
|
+
#def chown(user, group)
|
47
|
+
# util.chown(user, group, path)
|
48
|
+
#end
|
49
|
+
|
50
|
+
# Change the mode of this directory and all it's content
|
51
|
+
# recursively.
|
37
52
|
def chmod_r(mode)
|
38
53
|
util.chmod_r(mode, path)
|
39
54
|
end
|
40
55
|
#alias_method :chmod_R, :chmod_r
|
41
56
|
|
57
|
+
# Change the owner of this directory and all it's content
|
58
|
+
# recursively.
|
42
59
|
def chown_r(user, group)
|
43
60
|
util.chown_r(user, group, path)
|
44
61
|
end
|
@@ -48,33 +65,61 @@ module Folio
|
|
48
65
|
# ::Dir
|
49
66
|
#++
|
50
67
|
|
68
|
+
# Change into this directory.
|
51
69
|
def chdir(&block)
|
52
70
|
::Dir.chdir(path, &block)
|
53
71
|
end
|
54
72
|
alias_method :cd, :chdir
|
55
73
|
|
74
|
+
# Make this directory the file system root.
|
56
75
|
def chroot(&block)
|
57
76
|
::Dir.chroot(path, &block)
|
58
77
|
end
|
59
78
|
|
60
|
-
#
|
79
|
+
# Loop over the entries (this does includes '.' and '..').
|
80
|
+
def foreach(&block)
|
81
|
+
::Dir.foreach(path, &block)
|
82
|
+
end
|
83
|
+
|
84
|
+
# This returns a list of file names. Unlike traditional
|
85
|
+
# Dir.entries method, this does not include '.' or '..'.
|
61
86
|
def entries
|
62
|
-
::Dir.entries(path)
|
87
|
+
::Dir.entries(path) - ['.', '..']
|
63
88
|
end
|
64
89
|
|
65
|
-
|
66
|
-
|
90
|
+
# Returns a list of document names.
|
91
|
+
def document_entries
|
92
|
+
entries.select{|f| File.file?(File.join(path,f)) }
|
67
93
|
end
|
68
94
|
|
69
|
-
#
|
70
|
-
|
71
|
-
|
95
|
+
# Returns a list of directory names. This does not
|
96
|
+
# include '.' or '..'.
|
97
|
+
def directory_entries
|
98
|
+
dirs = ::Dir.glob("#{path}/")
|
99
|
+
dirs.collect{ |f| f.chomp('/') }
|
72
100
|
end
|
73
101
|
|
74
|
-
#
|
102
|
+
# Returns an Enumerator over all file objects in the directory.
|
103
|
+
def files
|
104
|
+
entries.to_enum(:each){ |f| FileObject[path, f] }
|
105
|
+
end
|
106
|
+
|
107
|
+
# Returns an Enumerator over all documents in the directory.
|
108
|
+
def documents
|
109
|
+
document_entries.to_enum(:each){ |f| FileObject[path, f] }
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns an Enumerator over all directories in the directory.
|
113
|
+
def directories
|
114
|
+
directory_entries.to_enum(:each){ |f| FileObject[path, f] }
|
115
|
+
end
|
116
|
+
|
117
|
+
# Join path and return new file object.
|
75
118
|
def /(fname)
|
76
119
|
FileObject[path, fname]
|
77
120
|
end
|
121
|
+
|
122
|
+
# Same as #/.
|
78
123
|
alias_method :+, :/
|
79
124
|
|
80
125
|
end
|
data/lib/folio/document.rb
CHANGED
@@ -14,7 +14,8 @@ module Folio
|
|
14
14
|
# Polymorphism
|
15
15
|
#++
|
16
16
|
|
17
|
-
def file? ; true ; end
|
17
|
+
#def file? ; true ; end
|
18
|
+
def document? ; true ; end
|
18
19
|
|
19
20
|
#--
|
20
21
|
# FileTest::
|
@@ -47,6 +48,18 @@ module Folio
|
|
47
48
|
::File.open(path, 'w'){|f| f.truncate(size)}
|
48
49
|
end
|
49
50
|
|
51
|
+
# Replace contents of file with string.
|
52
|
+
def write(string)
|
53
|
+
::File.open(path, 'w'){|f| f.write(string)}
|
54
|
+
end
|
55
|
+
alias_method :<, :write # NOTE: Sure about this? It means no Comparable.
|
56
|
+
|
57
|
+
# Replace contents of file with string.
|
58
|
+
def append(string)
|
59
|
+
::File.open(path, 'a'){|f| f.write(string)}
|
60
|
+
end
|
61
|
+
alias_method :<<, :append
|
62
|
+
|
50
63
|
#--
|
51
64
|
# Can we handle other modes besides read this way?
|
52
65
|
#++
|
data/lib/folio/fileobject.rb
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
require 'enumerator'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Enumerator
|
5
|
+
alias_method :list, :to_a
|
6
|
+
end
|
7
|
+
|
1
8
|
|
2
9
|
module Folio
|
3
10
|
|
@@ -149,7 +156,8 @@ module Folio
|
|
149
156
|
end
|
150
157
|
alias_method :stat!, :restat
|
151
158
|
|
152
|
-
def file? ; stat.file? ; end
|
159
|
+
#def file? ; stat.file? ; end
|
160
|
+
def document? ; stat.file? ; end
|
153
161
|
def directory? ; stat.directory? ; end
|
154
162
|
def blockdev? ; stat.blockdev? ; end
|
155
163
|
def chardev? ; stat.chardev? ; end
|
data/lib/folio/prompt.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
= Folio Prompt
|
4
|
+
|
5
|
+
A Folio Prompt object emulates a file system shell prompt in code.
|
6
|
+
|
7
|
+
=end
|
8
|
+
|
1
9
|
module Folio
|
2
10
|
|
3
11
|
# = Prompt class
|
4
12
|
#
|
5
13
|
class Prompt
|
6
14
|
|
7
|
-
|
15
|
+
# @work store the present working directory
|
16
|
+
# as a Directory object.
|
17
|
+
attr :work
|
8
18
|
|
9
19
|
#
|
10
20
|
def initialize(*path)
|
@@ -23,7 +33,8 @@ module Folio
|
|
23
33
|
@path = Directory.new(path)
|
24
34
|
end
|
25
35
|
|
26
|
-
#
|
36
|
+
# Opertaton mode. This can be :noop, :verbose or :dryrun.
|
37
|
+
# The later is the same as the first two combined.
|
27
38
|
def mode(opts=nil)
|
28
39
|
return @mode unless opts
|
29
40
|
opts.each do |key, val|
|
@@ -39,45 +50,45 @@ module Folio
|
|
39
50
|
end
|
40
51
|
end
|
41
52
|
|
42
|
-
def to_s ;
|
43
|
-
def pwd ; path ; end
|
53
|
+
def to_s ; work.to_s ; end
|
44
54
|
|
45
|
-
# Get the FileObject.
|
55
|
+
# Get the FileObject for the given file name.
|
46
56
|
def file(name)
|
47
57
|
FileObject(name)
|
48
58
|
end
|
49
|
-
|
50
|
-
#--
|
51
|
-
# ::Dir
|
52
|
-
#++
|
59
|
+
alias_method :[], :file
|
53
60
|
|
54
61
|
# Join paths.
|
55
62
|
def +(fname)
|
56
|
-
@
|
63
|
+
@work =+ fname
|
57
64
|
end
|
58
65
|
alias_method :/, :+
|
59
66
|
|
60
|
-
#
|
61
|
-
def paths
|
62
|
-
path.paths
|
63
|
-
end
|
64
|
-
|
65
|
-
# Directory entries.
|
67
|
+
# Lists all entries.
|
66
68
|
def entries
|
67
|
-
|
69
|
+
work.entries
|
68
70
|
end
|
69
71
|
alias_method :ls, :entries
|
70
72
|
|
71
|
-
#
|
72
|
-
def
|
73
|
-
|
73
|
+
# Lists directory entries.
|
74
|
+
def directory_entries
|
75
|
+
work.directory_entries
|
74
76
|
end
|
75
77
|
|
76
|
-
#
|
77
|
-
def
|
78
|
-
|
78
|
+
# Lists directory entries.
|
79
|
+
def document_entries
|
80
|
+
work.document_entries
|
79
81
|
end
|
80
82
|
|
83
|
+
# Returns Enumerator of files objects.
|
84
|
+
def files ; work.files ; end
|
85
|
+
|
86
|
+
# Returns Enumerator of directories.
|
87
|
+
def documents ; work.documents ; end
|
88
|
+
|
89
|
+
# Returns Enumerator of documents.
|
90
|
+
def directories ; work.directories ; end
|
91
|
+
|
81
92
|
# Glob pattern.
|
82
93
|
def glob(*patterns)
|
83
94
|
opts = (::Integer===patterns.last ? patterns.pop : 0)
|
@@ -88,9 +99,9 @@ module Folio
|
|
88
99
|
def cd(dir, &block)
|
89
100
|
#dir = localize(dir)
|
90
101
|
if block
|
91
|
-
@
|
102
|
+
@work.cd(dir, &block)
|
92
103
|
else
|
93
|
-
@
|
104
|
+
@work += dir
|
94
105
|
end
|
95
106
|
end
|
96
107
|
|
@@ -213,6 +224,7 @@ module Folio
|
|
213
224
|
end
|
214
225
|
end
|
215
226
|
|
227
|
+
# Returns FileUtils module based on mode.
|
216
228
|
def fileutils
|
217
229
|
return ::FileUtils unless @mode
|
218
230
|
case @mode
|
@@ -237,3 +249,31 @@ module Folio
|
|
237
249
|
|
238
250
|
end
|
239
251
|
|
252
|
+
|
253
|
+
# Could the prompt act as a delegate to file objects?
|
254
|
+
# If we did this then the file prompt could actually "cd" into a file.
|
255
|
+
#
|
256
|
+
=begin :nodoc:
|
257
|
+
def initialize(path)
|
258
|
+
@path = path = ::File.join(*path)
|
259
|
+
|
260
|
+
raise FileNotFound unless ::File.exist?(path)
|
261
|
+
|
262
|
+
if ::File.blockdev?(path) or chardev?(path)
|
263
|
+
@delegate = Device.new(path)
|
264
|
+
elsif ::File.link?(path)
|
265
|
+
@delegate = Link.new(path)
|
266
|
+
elsif ::File.directory?(path)
|
267
|
+
@delegate = Directory.new(path)
|
268
|
+
else
|
269
|
+
@delegate = Document.new(path)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def delete
|
274
|
+
@delegate.delete
|
275
|
+
@delegate = nil
|
276
|
+
end
|
277
|
+
=end
|
278
|
+
#++
|
279
|
+
|