folio 0.2.0 → 0.3.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.
Files changed (225) hide show
  1. data/CHANGES +12 -0
  2. data/MANIFEST +13 -227
  3. data/NEWS +8 -6
  4. data/TODO +8 -0
  5. data/VERSION +1 -0
  6. data/doc/book/basedir-spec-0.6.html +138 -0
  7. data/lib/folio.rb +16 -5
  8. data/lib/folio/directory.rb +8 -3
  9. data/lib/folio/document.rb +4 -0
  10. data/lib/folio/errors.rb +3 -0
  11. data/lib/folio/fileobject.rb +19 -10
  12. data/lib/folio/link.rb +10 -4
  13. data/lib/folio/pipe.rb +4 -0
  14. data/lib/folio/{prompt.rb → shell.rb} +92 -21
  15. data/lib/folio/xdg.rb +136 -0
  16. data/meta/abstract +1 -0
  17. data/meta/authors +1 -0
  18. data/meta/contact +1 -0
  19. data/meta/homepage +1 -0
  20. data/meta/releases +2 -0
  21. data/meta/summary +1 -0
  22. metadata +26 -239
  23. data/METADATA +0 -9
  24. data/doc/rdoc/classes/Enumerator.html +0 -92
  25. data/doc/rdoc/classes/Folio.html +0 -158
  26. data/doc/rdoc/classes/Folio/BlockDevice.html +0 -117
  27. data/doc/rdoc/classes/Folio/CharacterDevice.html +0 -117
  28. data/doc/rdoc/classes/Folio/Device.html +0 -119
  29. data/doc/rdoc/classes/Folio/Directory.html +0 -548
  30. data/doc/rdoc/classes/Folio/Document.html +0 -340
  31. data/doc/rdoc/classes/Folio/FileNotFound.html +0 -92
  32. data/doc/rdoc/classes/Folio/FileObject.html +0 -1205
  33. data/doc/rdoc/classes/Folio/Link.html +0 -238
  34. data/doc/rdoc/classes/Folio/Pipe.html +0 -131
  35. data/doc/rdoc/classes/Folio/Prompt.html +0 -839
  36. data/doc/rdoc/classes/Folio/Socket.html +0 -115
  37. data/doc/rdoc/created.rid +0 -1
  38. data/doc/rdoc/files/CHANGES.html +0 -92
  39. data/doc/rdoc/files/COPYING.html +0 -992
  40. data/doc/rdoc/files/METADATA.html +0 -102
  41. data/doc/rdoc/files/NEWS.html +0 -102
  42. data/doc/rdoc/files/README.html +0 -171
  43. data/doc/rdoc/files/lib/folio/device_rb.html +0 -96
  44. data/doc/rdoc/files/lib/folio/directory_rb.html +0 -96
  45. data/doc/rdoc/files/lib/folio/document_rb.html +0 -96
  46. data/doc/rdoc/files/lib/folio/errors_rb.html +0 -92
  47. data/doc/rdoc/files/lib/folio/fileobject_rb.html +0 -97
  48. data/doc/rdoc/files/lib/folio/link_rb.html +0 -96
  49. data/doc/rdoc/files/lib/folio/pipe_rb.html +0 -96
  50. data/doc/rdoc/files/lib/folio/prompt_rb.html +0 -92
  51. data/doc/rdoc/files/lib/folio/socket_rb.html +0 -96
  52. data/doc/rdoc/files/lib/folio_rb.html +0 -105
  53. data/doc/rdoc/fr_class_index.html +0 -59
  54. data/doc/rdoc/fr_file_index.html +0 -61
  55. data/doc/rdoc/fr_method_index.html +0 -195
  56. data/doc/rdoc/index.html +0 -26
  57. data/doc/rdoc/rdoc-style.css +0 -175
  58. data/doc/ri/Enumerator/cdesc-Enumerator.yaml +0 -15
  59. data/doc/ri/Folio/BlockDevice/blockdev%3f-i.yaml +0 -10
  60. data/doc/ri/Folio/BlockDevice/cdesc-BlockDevice.yaml +0 -18
  61. data/doc/ri/Folio/CharacterDevice/cdesc-CharacterDevice.yaml +0 -18
  62. data/doc/ri/Folio/CharacterDevice/chardev%3f-i.yaml +0 -10
  63. data/doc/ri/Folio/Device/cdesc-Device.yaml +0 -18
  64. data/doc/ri/Folio/Device/new-c.yaml +0 -10
  65. data/doc/ri/Folio/Directory/%2b-i.yaml +0 -12
  66. data/doc/ri/Folio/Directory/%2f-i.yaml +0 -13
  67. data/doc/ri/Folio/Directory/cd-i.yaml +0 -12
  68. data/doc/ri/Folio/Directory/cdesc-Directory.yaml +0 -57
  69. data/doc/ri/Folio/Directory/chdir-i.yaml +0 -13
  70. data/doc/ri/Folio/Directory/chmod_r-i.yaml +0 -12
  71. data/doc/ri/Folio/Directory/chown_r-i.yaml +0 -12
  72. data/doc/ri/Folio/Directory/chroot-i.yaml +0 -12
  73. data/doc/ri/Folio/Directory/cp_r-i.yaml +0 -12
  74. data/doc/ri/Folio/Directory/delete-i.yaml +0 -12
  75. data/doc/ri/Folio/Directory/directories-i.yaml +0 -12
  76. data/doc/ri/Folio/Directory/directory%3f-i.yaml +0 -10
  77. data/doc/ri/Folio/Directory/directory_entries-i.yaml +0 -12
  78. data/doc/ri/Folio/Directory/document_entries-i.yaml +0 -12
  79. data/doc/ri/Folio/Directory/documents-i.yaml +0 -12
  80. data/doc/ri/Folio/Directory/entries-i.yaml +0 -12
  81. data/doc/ri/Folio/Directory/files-i.yaml +0 -12
  82. data/doc/ri/Folio/Directory/foreach-i.yaml +0 -12
  83. data/doc/ri/Folio/Directory/new-c.yaml +0 -10
  84. data/doc/ri/Folio/Directory/rm_r-i.yaml +0 -12
  85. data/doc/ri/Folio/Directory/rm_rf-i.yaml +0 -12
  86. data/doc/ri/Folio/Directory/rmdir-i.yaml +0 -15
  87. data/doc/ri/Folio/Directory/unlink-i.yaml +0 -12
  88. data/doc/ri/Folio/Document/%3c%3c-i.yaml +0 -12
  89. data/doc/ri/Folio/Document/%3c-i.yaml +0 -12
  90. data/doc/ri/Folio/Document/append-i.yaml +0 -13
  91. data/doc/ri/Folio/Document/cdesc-Document.yaml +0 -42
  92. data/doc/ri/Folio/Document/delete-i.yaml +0 -10
  93. data/doc/ri/Folio/Document/document%3f-i.yaml +0 -12
  94. data/doc/ri/Folio/Document/executable%3f-i.yaml +0 -10
  95. data/doc/ri/Folio/Document/executable_real%3f-i.yaml +0 -10
  96. data/doc/ri/Folio/Document/intialize-i.yaml +0 -10
  97. data/doc/ri/Folio/Document/open-i.yaml +0 -10
  98. data/doc/ri/Folio/Document/read-i.yaml +0 -10
  99. data/doc/ri/Folio/Document/readlines-i.yaml +0 -10
  100. data/doc/ri/Folio/Document/truncate-i.yaml +0 -10
  101. data/doc/ri/Folio/Document/unlink-i.yaml +0 -12
  102. data/doc/ri/Folio/Document/write-i.yaml +0 -13
  103. data/doc/ri/Folio/FileNotFound/cdesc-FileNotFound.yaml +0 -15
  104. data/doc/ri/Folio/FileObject/%3c%3d%3e-i.yaml +0 -10
  105. data/doc/ri/Folio/FileObject/%3d%3d-i.yaml +0 -10
  106. data/doc/ri/Folio/FileObject/%5b%5d-c.yaml +0 -12
  107. data/doc/ri/Folio/FileObject/atime-i.yaml +0 -10
  108. data/doc/ri/Folio/FileObject/basename-i.yaml +0 -10
  109. data/doc/ri/Folio/FileObject/blockdev%3f-i.yaml +0 -10
  110. data/doc/ri/Folio/FileObject/cdesc-FileObject.yaml +0 -154
  111. data/doc/ri/Folio/FileObject/chardev%3f-i.yaml +0 -10
  112. data/doc/ri/Folio/FileObject/chmod-i.yaml +0 -10
  113. data/doc/ri/Folio/FileObject/chown-i.yaml +0 -10
  114. data/doc/ri/Folio/FileObject/cp-i.yaml +0 -12
  115. data/doc/ri/Folio/FileObject/ctime-i.yaml +0 -10
  116. data/doc/ri/Folio/FileObject/delete-i.yaml +0 -12
  117. data/doc/ri/Folio/FileObject/delete_force-i.yaml +0 -12
  118. data/doc/ri/Folio/FileObject/directory%3f-i.yaml +0 -10
  119. data/doc/ri/Folio/FileObject/dirname-i.yaml +0 -10
  120. data/doc/ri/Folio/FileObject/document%3f-i.yaml +0 -12
  121. data/doc/ri/Folio/FileObject/exist%3f-i.yaml +0 -13
  122. data/doc/ri/Folio/FileObject/exists%3f-i.yaml +0 -12
  123. data/doc/ri/Folio/FileObject/extname-i.yaml +0 -10
  124. data/doc/ri/Folio/FileObject/fnmatch%3f-i.yaml +0 -12
  125. data/doc/ri/Folio/FileObject/fnmatch-i.yaml +0 -11
  126. data/doc/ri/Folio/FileObject/grpowned%3f-i.yaml +0 -10
  127. data/doc/ri/Folio/FileObject/identical%3f-i.yaml +0 -10
  128. data/doc/ri/Folio/FileObject/inspect-i.yaml +0 -12
  129. data/doc/ri/Folio/FileObject/install-i.yaml +0 -12
  130. data/doc/ri/Folio/FileObject/link-i.yaml +0 -11
  131. data/doc/ri/Folio/FileObject/link_force-i.yaml +0 -11
  132. data/doc/ri/Folio/FileObject/ln-i.yaml +0 -12
  133. data/doc/ri/Folio/FileObject/ln_f-i.yaml +0 -12
  134. data/doc/ri/Folio/FileObject/ln_s-i.yaml +0 -12
  135. data/doc/ri/Folio/FileObject/ln_sf-i.yaml +0 -12
  136. data/doc/ri/Folio/FileObject/mtime-i.yaml +0 -10
  137. data/doc/ri/Folio/FileObject/mv-i.yaml +0 -12
  138. data/doc/ri/Folio/FileObject/new-c.yaml +0 -10
  139. data/doc/ri/Folio/FileObject/owned%3f-i.yaml +0 -10
  140. data/doc/ri/Folio/FileObject/pipe%3f-i.yaml +0 -10
  141. data/doc/ri/Folio/FileObject/readable%3f-i.yaml +0 -10
  142. data/doc/ri/Folio/FileObject/readable_real%3f-i.yaml +0 -10
  143. data/doc/ri/Folio/FileObject/relative-i.yaml +0 -12
  144. data/doc/ri/Folio/FileObject/rename-i.yaml +0 -11
  145. data/doc/ri/Folio/FileObject/restat-i.yaml +0 -13
  146. data/doc/ri/Folio/FileObject/rm-i.yaml +0 -12
  147. data/doc/ri/Folio/FileObject/rm_f-i.yaml +0 -12
  148. data/doc/ri/Folio/FileObject/setgid%3f-i.yaml +0 -10
  149. data/doc/ri/Folio/FileObject/setuid%3f-i.yaml +0 -10
  150. data/doc/ri/Folio/FileObject/size%3f-i.yaml +0 -10
  151. data/doc/ri/Folio/FileObject/size-i.yaml +0 -10
  152. data/doc/ri/Folio/FileObject/socket%3f-i.yaml +0 -10
  153. data/doc/ri/Folio/FileObject/split-i.yaml +0 -12
  154. data/doc/ri/Folio/FileObject/stat%21-i.yaml +0 -12
  155. data/doc/ri/Folio/FileObject/stat-i.yaml +0 -12
  156. data/doc/ri/Folio/FileObject/sticky%3f-i.yaml +0 -10
  157. data/doc/ri/Folio/FileObject/symlink-i.yaml +0 -11
  158. data/doc/ri/Folio/FileObject/symlink_force-i.yaml +0 -11
  159. data/doc/ri/Folio/FileObject/to_s-i.yaml +0 -12
  160. data/doc/ri/Folio/FileObject/touch-i.yaml +0 -10
  161. data/doc/ri/Folio/FileObject/unlink-i.yaml +0 -15
  162. data/doc/ri/Folio/FileObject/unlink_force-i.yaml +0 -13
  163. data/doc/ri/Folio/FileObject/util-i.yaml +0 -10
  164. data/doc/ri/Folio/FileObject/utime-i.yaml +0 -10
  165. data/doc/ri/Folio/FileObject/writable%3f-i.yaml +0 -10
  166. data/doc/ri/Folio/FileObject/writable_real%3f-i.yaml +0 -10
  167. data/doc/ri/Folio/FileObject/zero%3f-i.yaml +0 -10
  168. data/doc/ri/Folio/Link/cdesc-Link.yaml +0 -29
  169. data/doc/ri/Folio/Link/lchmod-i.yaml +0 -10
  170. data/doc/ri/Folio/Link/lchown-i.yaml +0 -10
  171. data/doc/ri/Folio/Link/link%3f-i.yaml +0 -10
  172. data/doc/ri/Folio/Link/lstat-i.yaml +0 -10
  173. data/doc/ri/Folio/Link/method_missing-i.yaml +0 -11
  174. data/doc/ri/Folio/Link/new-c.yaml +0 -10
  175. data/doc/ri/Folio/Link/readlink-i.yaml +0 -10
  176. data/doc/ri/Folio/Link/symlink%3f-i.yaml +0 -10
  177. data/doc/ri/Folio/Pipe/cdesc-Pipe.yaml +0 -17
  178. data/doc/ri/Folio/Pipe/new-c.yaml +0 -10
  179. data/doc/ri/Folio/Pipe/pipe%3f-i.yaml +0 -10
  180. data/doc/ri/Folio/Prompt/%2b-i.yaml +0 -13
  181. data/doc/ri/Folio/Prompt/%2f-i.yaml +0 -12
  182. data/doc/ri/Folio/Prompt/%5b%5d-c.yaml +0 -10
  183. data/doc/ri/Folio/Prompt/%5b%5d-i.yaml +0 -12
  184. data/doc/ri/Folio/Prompt/cd-i.yaml +0 -10
  185. data/doc/ri/Folio/Prompt/cdesc-Prompt.yaml +0 -95
  186. data/doc/ri/Folio/Prompt/chmod-i.yaml +0 -10
  187. data/doc/ri/Folio/Prompt/chmod_r-i.yaml +0 -10
  188. data/doc/ri/Folio/Prompt/chown-i.yaml +0 -12
  189. data/doc/ri/Folio/Prompt/chown_r-i.yaml +0 -10
  190. data/doc/ri/Folio/Prompt/cp-i.yaml +0 -12
  191. data/doc/ri/Folio/Prompt/cp_r-i.yaml +0 -12
  192. data/doc/ri/Folio/Prompt/directories-i.yaml +0 -12
  193. data/doc/ri/Folio/Prompt/directory_entries-i.yaml +0 -12
  194. data/doc/ri/Folio/Prompt/document_entries-i.yaml +0 -12
  195. data/doc/ri/Folio/Prompt/documents-i.yaml +0 -12
  196. data/doc/ri/Folio/Prompt/entries-i.yaml +0 -13
  197. data/doc/ri/Folio/Prompt/file-i.yaml +0 -13
  198. data/doc/ri/Folio/Prompt/files-i.yaml +0 -12
  199. data/doc/ri/Folio/Prompt/fileutils-i.yaml +0 -12
  200. data/doc/ri/Folio/Prompt/glob-i.yaml +0 -12
  201. data/doc/ri/Folio/Prompt/install-i.yaml +0 -10
  202. data/doc/ri/Folio/Prompt/ln-i.yaml +0 -12
  203. data/doc/ri/Folio/Prompt/ln_s-i.yaml +0 -12
  204. data/doc/ri/Folio/Prompt/ln_sf-i.yaml +0 -10
  205. data/doc/ri/Folio/Prompt/localize-i.yaml +0 -10
  206. data/doc/ri/Folio/Prompt/ls-i.yaml +0 -12
  207. data/doc/ri/Folio/Prompt/mkdir-i.yaml +0 -10
  208. data/doc/ri/Folio/Prompt/mkdir_p-i.yaml +0 -10
  209. data/doc/ri/Folio/Prompt/mode-i.yaml +0 -12
  210. data/doc/ri/Folio/Prompt/mv-i.yaml +0 -12
  211. data/doc/ri/Folio/Prompt/new-c.yaml +0 -11
  212. data/doc/ri/Folio/Prompt/rm-i.yaml +0 -10
  213. data/doc/ri/Folio/Prompt/rm_r-i.yaml +0 -10
  214. data/doc/ri/Folio/Prompt/rm_rf-i.yaml +0 -10
  215. data/doc/ri/Folio/Prompt/rmdir-i.yaml +0 -10
  216. data/doc/ri/Folio/Prompt/to_s-i.yaml +0 -10
  217. data/doc/ri/Folio/Prompt/touch-i.yaml +0 -12
  218. data/doc/ri/Folio/Socket/cdesc-Socket.yaml +0 -16
  219. data/doc/ri/Folio/Socket/new-c.yaml +0 -10
  220. data/doc/ri/Folio/cdesc-Folio.yaml +0 -15
  221. data/doc/ri/created.rid +0 -1
  222. data/test/fixture/bar.txt +0 -0
  223. data/test/fixture/foo.txt +0 -0
  224. data/test/test_folio.rb +0 -28
  225. data/test/test_helper.rb +0 -7
@@ -11,6 +11,11 @@ module Folio
11
11
 
12
12
  def directory? ; true ; end
13
13
 
14
+ # Opens up a Folio prompt at this directory.
15
+ def prompt
16
+ Folio::Prompt.new(self)
17
+ end
18
+
14
19
  # We have to use FileUtils here b/c of some obscure
15
20
  # secutiry issues.
16
21
 
@@ -101,17 +106,17 @@ module Folio
101
106
 
102
107
  # Returns an Enumerator over all file objects in the directory.
103
108
  def files
104
- entries.to_enum(:each){ |f| FileObject[path, f] }
109
+ entries.map{ |f| FileObject[path, f] }
105
110
  end
106
111
 
107
112
  # Returns an Enumerator over all documents in the directory.
108
113
  def documents
109
- document_entries.to_enum(:each){ |f| FileObject[path, f] }
114
+ document_entries.map{ |f| FileObject[path, f] }
110
115
  end
111
116
 
112
117
  # Returns an Enumerator over all directories in the directory.
113
118
  def directories
114
- directory_entries.to_enum(:each){ |f| FileObject[path, f] }
119
+ directory_entries.map{ |f| FileObject[path, f] }
115
120
  end
116
121
 
117
122
  # Join path and return new file object.
@@ -2,6 +2,10 @@ require 'folio/fileobject'
2
2
 
3
3
  module Folio
4
4
 
5
+ # = Document
6
+ #
7
+ # The Document class represents a FileObject.
8
+ #
5
9
  class Document < FileObject
6
10
 
7
11
  def intialize(path)
data/lib/folio/errors.rb CHANGED
@@ -3,5 +3,8 @@ module Folio
3
3
  class FileNotFound < ::IOError
4
4
  end
5
5
 
6
+ class LinkNotFound < ::IOError
7
+ end
8
+
6
9
  end
7
10
 
@@ -1,9 +1,9 @@
1
1
  require 'enumerator'
2
2
  require 'fileutils'
3
3
 
4
- class Enumerator
5
- alias_method :list, :to_a
6
- end
4
+ #class Enumerator
5
+ # alias_method :list, :to_a
6
+ #end
7
7
 
8
8
 
9
9
  module Folio
@@ -11,7 +11,7 @@ module Folio
11
11
  # = File Object
12
12
  #
13
13
  # Base class for all folio objects.
14
- #
14
+
15
15
  class FileObject
16
16
 
17
17
  Separator = ::File::Separator
@@ -20,7 +20,7 @@ module Folio
20
20
  def self.[](*path)
21
21
  path = ::File.join(*path)
22
22
 
23
- raise FileNotFound unless ::File.exist?(path)
23
+ raise FileNotFound, "#{path}" unless ::File.exist?(path)
24
24
 
25
25
  case ::File.ftype(path)
26
26
  when 'file'
@@ -45,15 +45,19 @@ module Folio
45
45
  private
46
46
 
47
47
  def initialize(path)
48
- raise FileNotFound unless ::File.exist?(path)
49
- @relpath = path
50
- @path = ::File.expand_path(path)
48
+ raise FileNotFound, "#{path}" unless ::File.exist?(path)
49
+ @path = ::File.expand_path(path)
51
50
  end
52
51
 
53
52
  public
54
53
 
55
54
  attr :path
56
- attr :relpath
55
+
56
+ def ==(other)
57
+ #p @path, other.path
58
+ return false unless FileObject===other
59
+ @path == other.path
60
+ end
57
61
 
58
62
  # This will alwasy be true, EXCEPT when
59
63
  # #rm, #delete or #unlink have been used.
@@ -62,6 +66,11 @@ module Folio
62
66
  end
63
67
  alias_method :exists?, :exist?
64
68
 
69
+ # Returns the parent directory object.
70
+ def parent
71
+ self.class[File.dirname(path)]
72
+ end
73
+
65
74
  #--
66
75
  # File Manipulation
67
76
  #++
@@ -90,7 +99,6 @@ module Folio
90
99
 
91
100
  def rename(dest)
92
101
  ::File.rename(path, dest)
93
- @relpath = dest
94
102
  @path = ::File.expand_path(dest)
95
103
  end
96
104
  alias_method :mv, :rename
@@ -137,6 +145,7 @@ module Folio
137
145
  util.install(path, dest, mode)
138
146
  end
139
147
 
148
+ #
140
149
  def touch
141
150
  util.touch(path)
142
151
  end
data/lib/folio/link.rb CHANGED
@@ -6,11 +6,17 @@ module Folio
6
6
 
7
7
  def initialize(path)
8
8
  super
9
- raise FileNotFound unless ::File.symlink?(@path)
9
+ raise LinkNotFound, "#{path}" unless ::File.symlink?(@path)
10
10
 
11
- @folio = Folio.new(::File.readlink(path))
11
+ dir = ::File.dirname(@path)
12
+ name = ::File.readlink(@path)
13
+ file = File.join(dir, name)
14
+
15
+ @target = Folio.file(file)
12
16
  end
13
17
 
18
+ attr :target
19
+
14
20
  #--
15
21
  # Am I write to think any file object can be linked?
16
22
  #++
@@ -39,9 +45,9 @@ module Folio
39
45
  ::File.lstat(path)
40
46
  end
41
47
 
42
- #
48
+ #
43
49
  def method_missing(s, *a, &b)
44
- @folio.send(s, *a, &b)
50
+ @target.send(s, *a, &b)
45
51
  end
46
52
 
47
53
  end
data/lib/folio/pipe.rb CHANGED
@@ -2,6 +2,10 @@ require 'folio/fileobject'
2
2
 
3
3
  module Folio
4
4
 
5
+ # = Pipe
6
+ #
7
+ # Is this the same as a FIFO?
8
+ #
5
9
  class Pipe < FileObject
6
10
 
7
11
  def initialize(path)
@@ -1,22 +1,13 @@
1
- =begin
2
-
3
- = Folio Prompt
4
-
5
- A Folio Prompt object emulates a file system shell prompt in code.
6
-
7
- =end
8
-
9
1
  module Folio
2
+ require 'folio/xdg'
10
3
 
11
4
  # = Prompt class
12
5
  #
13
- class Prompt
14
-
15
- # @work store the present working directory
16
- # as a Directory object.
17
- attr :work
6
+ # A Folio Shell object provides a limited file system shell in code.
7
+ #
8
+ class Shell
18
9
 
19
- #
10
+ # New Shell object.
20
11
  def initialize(*path)
21
12
  opts = (Hash===path.last ? path.pop : {})
22
13
  mode(opts)
@@ -27,10 +18,10 @@ module Folio
27
18
  path = File.join(*path)
28
19
  end
29
20
 
30
- raise FileNotFound unless ::File.exist?(path)
31
- raise FileNotFound unless ::File.directory?(path)
21
+ raise FileNotFound, "#{path}" unless ::File.exist?(path)
22
+ raise FileNotFound, "#{path}" unless ::File.directory?(path)
32
23
 
33
- @path = Directory.new(path)
24
+ @work = Directory.new(path)
34
25
  end
35
26
 
36
27
  # Opertaton mode. This can be :noop, :verbose or :dryrun.
@@ -50,12 +41,31 @@ module Folio
50
41
  end
51
42
  end
52
43
 
44
+ # String representation is work directory path.
53
45
  def to_s ; work.to_s ; end
54
46
 
47
+ # Present working directory as a Directory object.
48
+ attr :work
49
+
50
+ # Home location.
51
+ def home ; file('~') ; end
52
+
53
+ # Root location.
54
+ def root ; file('/') ; end
55
+
56
+ # Return a new prompt with the same location.
57
+ # NOTE: Use #dup or #clone ?
58
+ #def new ; Prompt.new(work) ; end
59
+
55
60
  # Get the FileObject for the given file name.
61
+ #
62
+ # TODO: Should there be methods like this for each
63
+ # type, and raise an error if not the right type?
64
+ #
56
65
  def file(name)
57
- FileObject(name)
66
+ FileObject[name]
58
67
  end
68
+
59
69
  alias_method :[], :file
60
70
 
61
71
  # Join paths.
@@ -96,6 +106,7 @@ module Folio
96
106
  ::Dir.glob(pattern, opts).each{ |f| FileObject[f] }
97
107
  end
98
108
 
109
+ # Chage working directory.
99
110
  def cd(dir, &block)
100
111
  #dir = localize(dir)
101
112
  if block
@@ -105,10 +116,11 @@ module Folio
105
116
  end
106
117
  end
107
118
 
108
- #--
109
- # fileutils
110
- #++
119
+ #############
120
+ # FileUtils #
121
+ #############
111
122
 
123
+ #
112
124
  def mkdir(dir, options)
113
125
  dir = localize(dir)
114
126
  fileutils.mkdir(dir, options)
@@ -213,6 +225,65 @@ module Folio
213
225
  fileutils.touch(list, options)
214
226
  end
215
227
 
228
+ #################
229
+ # XDG locations #
230
+ #################
231
+
232
+ # Look up a config file.
233
+ def config(path)
234
+ file(XDG.xdg_config_file(path))
235
+ end
236
+
237
+ # Look up a data file.
238
+ def data(path)
239
+ file(XDG.xdg_data_file(path))
240
+ end
241
+
242
+ # Look up a cache file.
243
+ def cache(path)
244
+ file(XDG.xdg_cache_file(path))
245
+ end
246
+
247
+ # Return a enumertor of system config directories.
248
+ def root_config() #_directories
249
+ XDG.xdg_config_dirs.to_enum(:each){ |f| file(f) }
250
+ end
251
+
252
+ # Return a enumertor of system data directories.
253
+ def root_data() #_directories
254
+ XDG.xdg_data_dirs.to_enum(:each){ |f| file(f) }
255
+ end
256
+
257
+ # Return the home config directory.
258
+ def home_config
259
+ file(XDG.xdg_config_home)
260
+ end
261
+
262
+ # Return the home data directory.
263
+ def home_data
264
+ file(XDG.xdg_data_home)
265
+ end
266
+
267
+ # Return the home cache directory.
268
+ def home_cache
269
+ file(XDG.xdg_cache_home)
270
+ end
271
+
272
+ # Return the home config directory.
273
+ def work_config
274
+ file(XDG.xdg_config_work)
275
+ end
276
+
277
+ # Return the home data directory.
278
+ def work_data
279
+ file(XDG.xdg_data_work)
280
+ end
281
+
282
+ # Return the home cache directory.
283
+ def work_cache
284
+ file(XDG.xdg_cache_work)
285
+ end
286
+
216
287
  private
217
288
 
218
289
  def localize(local_path)
data/lib/folio/xdg.rb ADDED
@@ -0,0 +1,136 @@
1
+ # :Title: Folio XDG
2
+ # :Author: &trans;
3
+ # :Copyright: (c)2008 Tiger Ops
4
+ # :License: GPLv3
5
+
6
+ module Folio
7
+
8
+ # = XDG Base Directory Standard
9
+ #
10
+ # This provides a conveient library for conforming to the
11
+ # XDG Base Directory Standard.
12
+ #
13
+ # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
14
+ #
15
+ # Some important clarifications, not made clear by the
16
+ # above specification.
17
+ #
18
+ # The data directories are for "read-only" files. In other words once
19
+ # something is put there, it should only be read, never written to
20
+ # by a program. (Generally speaking only users or pacakge mangers should
21
+ # be adding, changing or removing files from the data locations.
22
+ #
23
+ # The config locations are where you should store files that may change,
24
+ # and effect operations depending one there content. This is like etc/
25
+ # in the FHS, but alterable by end users and and end user programs,
26
+ # not just root and sudo admin scripts.
27
+ #
28
+ # The cache location stores files that could judt as well be deleted
29
+ # and everyihtng still works find. This is for variable and temporary
30
+ # files. Like var/ in FHS.
31
+ #
32
+ # This module returns paths as strings.
33
+ #
34
+ module XDG
35
+
36
+ ###############
37
+ module_function
38
+ ###############
39
+
40
+ def home
41
+ ENV['HOME'] || File.expand_path('~')
42
+ end
43
+
44
+ # Location of user's personal config directory.
45
+ def xdg_config_home
46
+ File.expand_path(
47
+ ENV['XDG_CONFIG_HOME'] || File.join(home, '.config')
48
+ )
49
+ end
50
+
51
+ # List of user's shared config directories.
52
+ def xdg_config_dirs
53
+ dirs = ENV['XDG_CONFIG_DIRS'].split(/[:;]/)
54
+ if dirs.empty?
55
+ dirs = %w{/etc/xdg}
56
+ end
57
+ dir.collect{ |d| File.expand_path(d) }
58
+ end
59
+
60
+ # Location of user's personal data directory.
61
+ def xdg_data_home
62
+ File.expand_path(
63
+ ENV['XDG_DATA_HOME'] || File.join(home, '.local', 'share')
64
+ )
65
+ end
66
+
67
+ # List of user's shared data directores.
68
+ def xdg_data_dirs
69
+ dirs = ENV['XDG_DATA_DIRS'].split(/[:;]/)
70
+ if dirs.empty?
71
+ dirs = %w{/usr/local/share/ /usr/share/}
72
+ end
73
+ dir.collect{ |d| File.expand_path(d) }
74
+ end
75
+
76
+ # Location of user's personal cache directory.
77
+ def xdg_cache_home
78
+ File.expand_path(
79
+ ENV['XDG_CACHE_HOME'] || File.join(home, '.cache')
80
+ )
81
+ end
82
+
83
+ # Find a file or directory in data dirs.
84
+ def xdg_data_file(file)
85
+ [data_home, *data_dirs].each do |dir|
86
+ path = File.join(dir,file)
87
+ break path if File.exist?(path)
88
+ end
89
+ end
90
+
91
+ # Find a file or directory in config dirs.
92
+ def xdg_config_file(file)
93
+ [config_home, *config_dirs].each do |dir|
94
+ path = File.join(dir,file)
95
+ break path if File.exist?(path)
96
+ end
97
+ end
98
+
99
+ # Find a file or directory in the user cache.
100
+ def xdg_cache_file(file)
101
+ File.join(cache_home,file)
102
+ end
103
+
104
+ ############################################
105
+ # The following are not strictly XDG spec, #
106
+ # but are useful in the same respect. #
107
+ ############################################
108
+
109
+ # Location of working config directory.
110
+ def xdg_config_work
111
+ File.expand_path(
112
+ #ENV['XDG_CONFIG_WORK'] || File.join(Dir.pwd, '.config')
113
+ File.join(Dir.pwd, '.config')
114
+ )
115
+ end
116
+
117
+ # Location of working data directory.
118
+ def xdg_data_work
119
+ File.expand_path(
120
+ #ENV['XDG_DATA_WORK'] || File.join(Dir.pwd, '.share')
121
+ File.join(Dir.pwd, '.share')
122
+ )
123
+ end
124
+
125
+ # Location of working cache directory.
126
+ def xdg_cache_work
127
+ File.expand_path(
128
+ #ENV['XDG_CACHE_WORK'] || File.join(Dir.pwd, '.cache')
129
+ File.join(Dir.pwd, '.cache')
130
+ )
131
+ end
132
+
133
+ end # module XDG
134
+
135
+ end # module Folio
136
+