fsdb 0.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/{RELEASE-NOTES → History.txt} +6 -0
  2. data/{README → README.txt} +26 -17
  3. data/examples/flat.rb +146 -0
  4. data/examples/fsdb-example.rb +28 -0
  5. data/examples/rbformat.rb +17 -0
  6. data/examples/yaml2.rb +29 -0
  7. data/junk/OLDRakefile +98 -0
  8. data/junk/OLDRakefile2 +55 -0
  9. data/junk/check-cache.rb +18 -0
  10. data/junk/create-lock.rb +25 -0
  11. data/junk/doc/old-api/classes/FSDB.html +139 -0
  12. data/junk/doc/old-api/classes/FSDB/Database.html +953 -0
  13. data/junk/doc/old-api/classes/FSDB/Database.src/M000029.html +16 -0
  14. data/junk/doc/old-api/classes/FSDB/Database.src/M000030.html +16 -0
  15. data/junk/doc/old-api/classes/FSDB/Database.src/M000031.html +16 -0
  16. data/junk/doc/old-api/classes/FSDB/Database.src/M000032.html +16 -0
  17. data/junk/doc/old-api/classes/FSDB/Database.src/M000033.html +33 -0
  18. data/junk/doc/old-api/classes/FSDB/Database.src/M000034.html +18 -0
  19. data/junk/doc/old-api/classes/FSDB/Database.src/M000035.html +22 -0
  20. data/junk/doc/old-api/classes/FSDB/Database.src/M000036.html +16 -0
  21. data/junk/doc/old-api/classes/FSDB/Database.src/M000037.html +22 -0
  22. data/junk/doc/old-api/classes/FSDB/Database.src/M000038.html +43 -0
  23. data/junk/doc/old-api/classes/FSDB/Database.src/M000039.html +25 -0
  24. data/junk/doc/old-api/classes/FSDB/Database.src/M000040.html +43 -0
  25. data/junk/doc/old-api/classes/FSDB/Database.src/M000041.html +23 -0
  26. data/junk/doc/old-api/classes/FSDB/Database.src/M000042.html +22 -0
  27. data/junk/doc/old-api/classes/FSDB/Database.src/M000043.html +16 -0
  28. data/junk/doc/old-api/classes/FSDB/Database.src/M000044.html +16 -0
  29. data/junk/doc/old-api/classes/FSDB/Database.src/M000045.html +18 -0
  30. data/junk/doc/old-api/classes/FSDB/Database.src/M000046.html +18 -0
  31. data/junk/doc/old-api/classes/FSDB/Database.src/M000047.html +18 -0
  32. data/junk/doc/old-api/classes/FSDB/Database.src/M000048.html +16 -0
  33. data/junk/doc/old-api/classes/FSDB/Database.src/M000049.html +71 -0
  34. data/junk/doc/old-api/classes/FSDB/Database.src/M000050.html +43 -0
  35. data/junk/doc/old-api/classes/FSDB/Database.src/M000051.html +53 -0
  36. data/junk/doc/old-api/classes/FSDB/Database.src/M000052.html +44 -0
  37. data/junk/doc/old-api/classes/FSDB/Database.src/M000053.html +39 -0
  38. data/junk/doc/old-api/classes/FSDB/Database.src/M000054.html +72 -0
  39. data/junk/doc/old-api/classes/FSDB/Database.src/M000055.html +39 -0
  40. data/junk/doc/old-api/classes/FSDB/Database.src/M000056.html +18 -0
  41. data/junk/doc/old-api/classes/FSDB/Database.src/M000057.html +18 -0
  42. data/junk/doc/old-api/classes/FSDB/Database.src/M000058.html +18 -0
  43. data/junk/doc/old-api/classes/FSDB/Database.src/M000059.html +18 -0
  44. data/junk/doc/old-api/classes/FSDB/Database.src/M000060.html +18 -0
  45. data/junk/doc/old-api/classes/FSDB/Database.src/M000061.html +23 -0
  46. data/junk/doc/old-api/classes/FSDB/Database.src/M000062.html +23 -0
  47. data/junk/doc/old-api/classes/FSDB/Database.src/M000063.html +18 -0
  48. data/junk/doc/old-api/classes/FSDB/Database.src/M000064.html +18 -0
  49. data/junk/doc/old-api/classes/FSDB/Database/AbortedTransaction.html +118 -0
  50. data/junk/doc/old-api/classes/FSDB/Database/CreateFileError.html +120 -0
  51. data/junk/doc/old-api/classes/FSDB/Database/DirIsImmutableError.html +117 -0
  52. data/junk/doc/old-api/classes/FSDB/Database/DirNotEmptyError.html +117 -0
  53. data/junk/doc/old-api/classes/FSDB/Database/FormatError.html +117 -0
  54. data/junk/doc/old-api/classes/FSDB/Database/MissingFileError.html +117 -0
  55. data/junk/doc/old-api/classes/FSDB/Database/MissingObjectError.html +117 -0
  56. data/junk/doc/old-api/classes/FSDB/Database/NotDirError.html +118 -0
  57. data/junk/doc/old-api/classes/FSDB/Database/PathComponentError.html +120 -0
  58. data/junk/doc/old-api/classes/FSDB/DatabaseDebuggable.html +148 -0
  59. data/junk/doc/old-api/classes/FSDB/DatabaseDebuggable.src/M000005.html +21 -0
  60. data/junk/doc/old-api/classes/FSDB/DatabaseDebuggable.src/M000007.html +21 -0
  61. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.html +210 -0
  62. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000006.html +22 -0
  63. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000007.html +22 -0
  64. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000008.html +22 -0
  65. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000009.html +22 -0
  66. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000010.html +22 -0
  67. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000011.html +22 -0
  68. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000012.html +22 -0
  69. data/junk/doc/old-api/classes/FSDB/DirectoryIterators.src/M000013.html +22 -0
  70. data/junk/doc/old-api/classes/FSDB/ForkSafely.html +126 -0
  71. data/junk/doc/old-api/classes/FSDB/Modex.html +237 -0
  72. data/junk/doc/old-api/classes/FSDB/Modex.src/M000024.html +21 -0
  73. data/junk/doc/old-api/classes/FSDB/Modex.src/M000025.html +30 -0
  74. data/junk/doc/old-api/classes/FSDB/Modex.src/M000026.html +21 -0
  75. data/junk/doc/old-api/classes/FSDB/Modex.src/M000027.html +30 -0
  76. data/junk/doc/old-api/classes/FSDB/Modex.src/M000028.html +44 -0
  77. data/junk/doc/old-api/classes/FSDB/Modex.src/M000029.html +26 -0
  78. data/junk/doc/old-api/classes/FSDB/Modex.src/M000030.html +48 -0
  79. data/junk/doc/old-api/classes/FSDB/Modex/ForkSafely.html +105 -0
  80. data/junk/doc/old-api/classes/FSDB/Mutex.html +244 -0
  81. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000018.html +19 -0
  82. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000019.html +18 -0
  83. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000020.html +19 -0
  84. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000021.html +18 -0
  85. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000022.html +23 -0
  86. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000023.html +30 -0
  87. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000024.html +26 -0
  88. data/junk/doc/old-api/classes/FSDB/Mutex.src/M000025.html +21 -0
  89. data/junk/doc/old-api/classes/FSDB/Mutex/ForkSafely.html +105 -0
  90. data/junk/doc/old-api/classes/FSDB/PathUtilities.html +257 -0
  91. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000012.html +23 -0
  92. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000013.html +18 -0
  93. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000014.html +23 -0
  94. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000015.html +18 -0
  95. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000016.html +18 -0
  96. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000017.html +22 -0
  97. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000018.html +23 -0
  98. data/junk/doc/old-api/classes/FSDB/PathUtilities.src/M000019.html +18 -0
  99. data/junk/doc/old-api/classes/FSDB/PathUtilities/InvalidPathError.html +111 -0
  100. data/junk/doc/old-api/classes/File.html +272 -0
  101. data/junk/doc/old-api/classes/File.src/M000001.html +17 -0
  102. data/junk/doc/old-api/classes/File.src/M000002.html +17 -0
  103. data/junk/doc/old-api/classes/File.src/M000003.html +20 -0
  104. data/junk/doc/old-api/classes/File.src/M000004.html +20 -0
  105. data/junk/doc/old-api/classes/File.src/M000005.html +32 -0
  106. data/junk/doc/old-api/classes/File.src/M000006.html +32 -0
  107. data/junk/doc/old-api/created.rid +1 -0
  108. data/junk/doc/old-api/files/README.html +112 -0
  109. data/junk/doc/old-api/files/RELEASE-NOTES.html +233 -0
  110. data/junk/doc/old-api/files/fsdb_txt.html +888 -0
  111. data/junk/doc/old-api/files/lib/fsdb/database_rb.html +115 -0
  112. data/junk/doc/old-api/files/lib/fsdb/file-lock_rb.html +109 -0
  113. data/junk/doc/old-api/files/lib/fsdb/modex_rb.html +121 -0
  114. data/junk/doc/old-api/files/lib/fsdb/mutex_rb.html +108 -0
  115. data/junk/doc/old-api/files/lib/fsdb/util_rb.html +108 -0
  116. data/junk/doc/old-api/fr_class_index.html +47 -0
  117. data/junk/doc/old-api/fr_file_index.html +34 -0
  118. data/junk/doc/old-api/fr_method_index.html +90 -0
  119. data/junk/doc/old-api/index.html +24 -0
  120. data/junk/doc/old-api/rdoc-style.css +208 -0
  121. data/junk/file-lock-nb.rb +15 -0
  122. data/junk/fl.rb +144 -0
  123. data/junk/flock-test.rb +39 -0
  124. data/junk/fsdb.kateproject +47 -0
  125. data/junk/fsdb.prj +196 -0
  126. data/junk/fsdb.sf +46 -0
  127. data/junk/insert-dir.rb +48 -0
  128. data/junk/lock-test-bug.rb +150 -0
  129. data/junk/lock-test-too-simple.rb +136 -0
  130. data/junk/lock-test.rb +151 -0
  131. data/{script → junk}/mkrdoc +0 -0
  132. data/junk/restore-fsdb.rb +37 -0
  133. data/junk/rf.txt +5 -0
  134. data/junk/solaris-bug-fixed.rb +184 -0
  135. data/junk/solaris-bug.rb +182 -0
  136. data/junk/solaris-bug.txt +43 -0
  137. data/junk/sync.rb +327 -0
  138. data/junk/test-file-lock.html +86 -0
  139. data/junk/test-file-lock.rb +84 -0
  140. data/junk/test-processes.rb +131 -0
  141. data/junk/test-threads.rb +113 -0
  142. data/junk/wiki-mutex.rb +108 -0
  143. data/lib/fsdb/database.rb +5 -3
  144. data/lib/fsdb/delegatable.rb +21 -0
  145. data/lib/fsdb/faster-modex.rb +223 -0
  146. data/lib/fsdb/faster-mutex.rb +138 -0
  147. data/lib/fsdb/mutex.rb +4 -1
  148. data/lib/fsdb/persistent.rb +91 -0
  149. data/lib/fsdb/read-write-object.rb +36 -0
  150. data/lib/fsdb/server.rb +44 -0
  151. data/misc/fsdb-blorubu.txt +47 -0
  152. data/misc/mtime-and-file-id.txt +23 -0
  153. data/misc/posixlock.txt +148 -0
  154. data/rakefile +39 -0
  155. data/tasks/ann.rake +80 -0
  156. data/tasks/bones.rake +20 -0
  157. data/tasks/gem.rake +201 -0
  158. data/tasks/git.rake +40 -0
  159. data/tasks/notes.rake +27 -0
  160. data/tasks/post_load.rake +34 -0
  161. data/tasks/rdoc.rake +51 -0
  162. data/tasks/rubyforge.rake +55 -0
  163. data/tasks/setup.rb +292 -0
  164. data/tasks/spec.rake +54 -0
  165. data/tasks/svn.rake +47 -0
  166. data/tasks/test.rake +40 -0
  167. data/tasks/zentest.rake +36 -0
  168. data/test/err.txt +31 -0
  169. data/test/runs.rb +8 -0
  170. data/test/test-file-lock.rb +78 -0
  171. data/test/test-util.rb +1 -0
  172. data/test/trap.rb +31 -0
  173. metadata +198 -35
  174. data/Manifest +0 -36
  175. data/Rakefile +0 -10
  176. data/fsdb.gemspec +0 -113
@@ -1,3 +1,9 @@
1
+ fsdb 0.6.0
2
+
3
+ - Replaced ftools with fileutils.
4
+
5
+ - Released as a gem using Mr. Bones.
6
+
1
7
  fsdb 0.5
2
8
 
3
9
  - If ruby is 1.8.2 or later, flock doesn't block other threads, so accessing
@@ -12,8 +12,16 @@ FSDB does not yet have any indexing or querying mechanisms, and is probably miss
12
12
 
13
13
  == Installation
14
14
 
15
+ For .gem:
16
+
15
17
  gem install fsdb
16
18
 
19
+ For .tgz, unpack and then:
20
+
21
+ ruby install.rb config
22
+ ruby install.rb setup
23
+ ruby install.rb install
24
+
17
25
  == Synopsis
18
26
 
19
27
  require 'fsdb'
@@ -71,8 +79,8 @@ Keys in the database are path strings, which are simply strings in the usual for
71
79
  foo//bar
72
80
  foo/../foo/bar
73
81
 
74
- work correctly, as do paths that denote hard or soft links, if supported on
75
- the platform.
82
+ work correctly (they access the same objects), as do paths that denote hard
83
+ or soft links, if supported on the platform.
76
84
 
77
85
  Links are subject to the same naming convention as normal files with regard
78
86
  to format identification: format is determined by the path within the
@@ -136,12 +144,11 @@ There are two kinds of transactions:
136
144
  with one that does not have the <tt>+</tt> method or the <tt>[ ]</tt> method.
137
145
  The four operations are atomic by themselves, but the sequence is not.
138
146
 
139
- Note that changes to a database object using this kind of transaction
140
- cannot be made using destructive methods (such as <tt><<</tt>) but only by
141
- assignments of the form <tt>db[<path>] = <data></tt>. Note that
142
- <tt>+=</tt> and similar "assignment operators" can be used but are not atomic,
143
- because
144
-
147
+ Note that changes to a database object using this kind of transaction cannot
148
+ be made using destructive methods (such as <tt><<</tt>) but only by
149
+ assignments of the form <tt>db[<path>] = <data></tt>. Note that <tt>+=</tt>
150
+ and similar "assignment operators" can be used but are not atomic, because
151
+
145
152
  db[<path>] += 1
146
153
 
147
154
  is really
@@ -163,7 +170,7 @@ There are two kinds of transactions:
163
170
 
164
171
  This guarantees that, if the object at the path is still <tt>[1, 2, 3]</tt>
165
172
  at the time of the #edit call, the value returned by the transaction will be
166
- +4+.
173
+ 4.
167
174
 
168
175
  Simply put, #edit allows exclusive write access to the object at the path for
169
176
  the duration of the block. Other threads or processes that use FSDB methods
@@ -263,7 +270,7 @@ FSDB has been tested on the following platforms and file systems:
263
270
 
264
271
  - Windows ME (single cpu, FAT32)
265
272
 
266
- FSDB is currently tested with ruby-1.9.0 and ruby-1.8.1.
273
+ FSDB is currently tested with ruby-1.9.1 and ruby-1.8.6.
267
274
 
268
275
  On windows, both the mswin32 and mingw32 builds of ruby have been used with FSDB. It has never been tested with cygwin or bccwin.
269
276
 
@@ -304,12 +311,12 @@ FSDB is not very fast. It's useful more for its safety, flexibility, and ease of
304
311
 
305
312
  - For speed, avoid using #fetch and its alias #[]. As noted in the API docs,
306
313
  these methods cannot safely return the same object that is cached, so must
307
- clear out the cache's reference to the object so that is will be loaded
314
+ clear out the cache's reference to the object so that it will be loaded
308
315
  freshly the next time #fetch is called on the path.
309
316
 
310
317
  The performance hit of #fetch is of course greater with larger objects,
311
318
  and with objects that are loaded by a more complex procedure, such as
312
- Masrshal.load.
319
+ Marshal.load.
313
320
 
314
321
  You can think of #fetch as a "deep copy" of the object. If you call it twice,
315
322
  you get different copies that do not share any parts. Or you can think of it
@@ -372,7 +379,7 @@ FSDB is not very fast. It's useful more for its safety, flexibility, and ease of
372
379
  - It may be fast enough for many purposes, especially using multiple processes
373
380
  rather than multiple threads.
374
381
 
375
- - Pure ruby. Ruby license. Free sotware.
382
+ - Pure ruby. Ruby license. Free software.
376
383
 
377
384
 
378
385
  == Applications
@@ -396,6 +403,8 @@ is:
396
403
 
397
404
  === Features
398
405
 
406
+ - Should the Format objects be classes instead of just instances of Format?
407
+
399
408
  - Default value and proc for Database, like Hash.
400
409
 
401
410
  - FSDB::Reference class:
@@ -460,6 +469,8 @@ is:
460
469
 
461
470
  - more formats
462
471
 
472
+ - json
473
+
463
474
  - tabular data, excel, xml, ascii db, csv
464
475
 
465
476
  - SOAP marshal, XML marshal
@@ -520,9 +531,7 @@ is:
520
531
  wipe the reference to the object, and could leave the contents string. But
521
532
  this would increase file size and duplicate the file system's own cache.
522
533
 
523
- == Version
524
-
525
- fsdb 0.5
534
+ == Web site
526
535
 
527
536
  The current version of this software can be found at http://redshift.sourceforge.net/fsdb.
528
537
 
@@ -533,4 +542,4 @@ This software is distributed under the Ruby license. See http://www.ruby-lang.or
533
542
  == Author
534
543
 
535
544
  Joel VanderWerf, mailto:vjoel@users.sourceforge.net
536
- Copyright (c) 2005, Joel VanderWerf.
545
+ Copyright (c) 2003-2009, Joel VanderWerf.
data/examples/flat.rb ADDED
@@ -0,0 +1,146 @@
1
+ # Fast, flat storage based on Kirk Haines' technique.
2
+
3
+ require 'fsdb'
4
+ require 'digest/md5'
5
+
6
+ class FlatDB < FSDB::Database
7
+
8
+ def initialize(path, depth = 2)
9
+ raise ArgumentError, "Invalid depth #{depth} > 32" if depth > 32
10
+
11
+ @path_from_key = {}
12
+ @path_pat = Regexp.new("^" + "(..)"*depth)
13
+ @depth = depth
14
+
15
+ super(path)
16
+ end
17
+
18
+ def path_from_key(key)
19
+ path = @path_from_key[key]
20
+ unless path
21
+ if @depth > 0
22
+ path_components = Digest::MD5.hexdigest(key).scan(@path_pat).first
23
+ path_components << key
24
+ path = path_components.join("/")
25
+ else
26
+ path = key
27
+ end
28
+ @path_from_key[key] = path
29
+ end
30
+ path
31
+ end
32
+
33
+ def browse(key)
34
+ super path_from_key(key)
35
+ end
36
+
37
+ def edit(key)
38
+ super path_from_key(key)
39
+ end
40
+
41
+ def replace(key)
42
+ super path_from_key(key)
43
+ end
44
+
45
+ def delete(key, load=true)
46
+ @path_from_key.delete key ## should probably purge this hash periodically
47
+ super path_from_key(key), load
48
+ end
49
+
50
+ # don't bother with #insert, #fetch, #[], #[]= since they are
51
+ # inherently less efficient
52
+ end
53
+
54
+ db = FlatDB.new('/tmp/fsdb/flat', 2)
55
+
56
+ db.replace 'foo.txt' do
57
+ "this is the foo text"
58
+ end
59
+
60
+ db.browse 'foo.txt' do |x|
61
+ p x
62
+ end
63
+
64
+ # key names can have '/' in them, in which case they reference deeper subdirs
65
+ db.replace 'sub/foo.txt' do
66
+ "this is the subdir's foo text"
67
+ end
68
+
69
+ db.browse 'sub/foo.txt' do |x|
70
+ p x
71
+ end
72
+
73
+ require 'benchmark'
74
+
75
+ Benchmark.bm(10) do |bm|
76
+ nfiles = 100
77
+
78
+ [0,1,2].each do |depth|
79
+ db = FlatDB.new("/tmp/fsdb/depth_#{depth}", depth)
80
+
81
+ puts "\ndepth=#{depth}"
82
+
83
+ bm.report "create" do
84
+ nfiles.times do |i|
85
+ db.replace i.to_s do # with a filename like that, will use marshal
86
+ i
87
+ end
88
+ end
89
+ end
90
+
91
+ bm.report "access" do
92
+ nfiles.times do |i|
93
+ db.browse i.to_s do |j|
94
+ raise unless i == j
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ __END__
102
+
103
+ N=100_000
104
+ user system total real
105
+
106
+ depth=0
107
+ create 72.680000 1772.030000 1844.710000 (1853.686824)
108
+ access 55.780000 13.090000 68.870000 ( 97.170382)
109
+
110
+ depth=1
111
+ create 125.170000 24.250000 149.420000 (329.576419)
112
+ access 143.210000 12.040000 155.250000 (759.768371)
113
+
114
+ depth=2
115
+ create 263.900000 32.570000 296.470000 (1950.482468)
116
+ access 195.200000 17.250000 212.450000 (1562.214063)
117
+
118
+ # du -sk depth_0
119
+ 804236 depth_0
120
+ # du -sk depth_1
121
+ 804832 depth_1
122
+ # du -sk depth_2
123
+ 1006408 depth_2
124
+
125
+ Output of two successive runs, first without the db files already existing (N=10000, depth=2):
126
+
127
+ $ ruby flat.rb
128
+ user system total real
129
+ create 5.270000 2.520000 7.790000 ( 41.684685)
130
+ access 2.210000 0.380000 2.590000 ( 2.626480)
131
+ $ ruby flat.rb
132
+ user system total real
133
+ create 3.020000 1.930000 4.950000 ( 5.954889)
134
+ access 1.830000 0.280000 2.110000 ( 2.157327)
135
+
136
+ Output of two successive runs, first without the db files already existing (N=10000, depth=0):
137
+
138
+ $ ruby flat.rb
139
+ user system total real
140
+ create 2.780000 18.710000 21.490000 ( 22.292284)
141
+ access 1.800000 0.230000 2.030000 ( 2.044320)
142
+ $ ruby flat.rb
143
+ user system total real
144
+ create 3.280000 2.550000 5.830000 ( 6.105209)
145
+ access 1.790000 0.300000 2.090000 ( 2.200052)
146
+
@@ -0,0 +1,28 @@
1
+ require 'fsdb' # http://redshift.sourceforge.net/fsdb
2
+
3
+ db = FSDB::Database.new("~/tmp")
4
+
5
+ # Tell FSDB to use YAML format when it sees ".yml" and ".yaml" suffixes.
6
+ # It is easy to extend the recognition rules to handle other formats.
7
+ db.formats = [FSDB::YAML_FORMAT] + db.formats
8
+
9
+ # Write (atomically) the initial data to the file.
10
+ db["config.yml"] = { "key1" => 111, "key2" => 222 }
11
+
12
+ # Enter a thread-safe and process-safe transaction to
13
+ # change the state of the file.
14
+ db.edit("config.yml") do |cfg|
15
+ cfg['key1'] = 'aaa'
16
+ cfg['key2'] = 'bbb'
17
+ end
18
+
19
+ # Check that it works.
20
+ puts File.read(File.expand_path("~/tmp/config.yml"))
21
+
22
+ __END__
23
+
24
+ Output:
25
+
26
+ ---
27
+ key1: aaa
28
+ key2: bbb
@@ -0,0 +1,17 @@
1
+ require 'fsdb'
2
+
3
+ dir ='~/tmp/fsdb/rb-format'
4
+ db = FSDB::Database.new(dir)
5
+
6
+ RUBY_FORMAT =
7
+ FSDB::Format.new(
8
+ /\.rb$/i,
9
+ :name => "RUBY_FORMAT",
10
+ :load => proc {|f| eval "proc {#{f.read}}"},
11
+ :dump => proc {|string, f| f.syswrite(string)}
12
+ )
13
+
14
+ db.formats = [ RUBY_FORMAT ]
15
+
16
+ db['some-script.rb'] = "|x| 1+2+x"
17
+ p db['some-script.rb'][3]
data/examples/yaml2.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'fsdb'
2
+ require 'yaml'
3
+
4
+ dir = File.join(ENV['TMPDIR'] || ENV['TMP'] || 'tmp', "my_data")
5
+
6
+ db = FSDB::Database.new dir
7
+ db.formats = [FSDB::YAML_FORMAT] + db.formats
8
+
9
+ 3.times do |i|
10
+ db["Cat#{i}.yml"] = %w{
11
+ name1
12
+ name2
13
+ name3
14
+ }
15
+ end
16
+
17
+ path = "Cat1.yml"
18
+
19
+ puts "Here's the object:"
20
+ puts "=================="
21
+ p db[path]
22
+ puts "=================="
23
+ puts
24
+
25
+ puts "Here's the file:"
26
+ puts "=================="
27
+ puts File.read(File.join(db.dir, path))
28
+ puts "=================="
29
+ puts
data/junk/OLDRakefile ADDED
@@ -0,0 +1,98 @@
1
+
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/contrib/sshpublisher'
5
+ require 'rake/gempackagetask'
6
+
7
+ PKG_VERSION = IO::read 'VERSION'
8
+ PKG_VERSION.strip!
9
+ PKG_NAME = "fsdb"
10
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
+
12
+ #-----------------------------------------------------------------------
13
+ desc "Default Task"
14
+ task :default => :package
15
+
16
+ #-----------------------------------------------------------------------
17
+ # cleanup
18
+ #-----------------------------------------------------------------------
19
+ CLOBBER.include(
20
+ "pkg/**",
21
+ "README"
22
+ )
23
+ #-----------------------------------------------------------------------
24
+ # generate README
25
+ #
26
+ # - maybe make a task lib out of the gen_readme.rb code ?
27
+ #
28
+ #-----------------------------------------------------------------------
29
+ desc "Generate README"
30
+ task :readme => [:clobber] do
31
+ File.open('README','w') do |f|
32
+ $stdout = f
33
+ tmpl = IO::read 'gen_readme.rb'
34
+ eval tmpl
35
+ $stdout = STDOUT
36
+ end
37
+ end
38
+
39
+
40
+ #-----------------------------------------------------------------------
41
+ # Publish to website
42
+ #-----------------------------------------------------------------------
43
+ desc "Publish the gem on codeforpeople.com"
44
+
45
+ PUBLISH_HOST = "codeforpeople.com"
46
+ PUBLISH_ROOT = "/lib/ruby"
47
+ task :publish => [:package] do
48
+ `ssh #{PUBLISH_HOST} 'mkdir -p #{PUBLISH_ROOT}/#{PKG_NAME}/#{PKG_FILE_NAME}'`
49
+ `scp -rq ./ #{PUBLISH_HOST}:#{PUBLISH_ROOT}/#{PKG_NAME}/#{PKG_FILE_NAME}`
50
+
51
+ # if packages should go somewhere else
52
+ Rake::SshFilePublisher.new(PUBLISH_HOST, "#{PUBLISH_ROOT}/pkg", "pkg", "#{PKG_FILE_NAME}.zip").upload
53
+ Rake::SshFilePublisher.new(PUBLISH_HOST, "#{PUBLISH_ROOT}/pkg", "pkg", "#{PKG_FILE_NAME}.tgz").upload
54
+ Rake::SshFilePublisher.new(PUBLISH_HOST, "#{PUBLISH_ROOT}/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
55
+
56
+ end
57
+
58
+ #-----------------------------------------------------------------------
59
+ # install
60
+ #-----------------------------------------------------------------------
61
+ task :install => [:package] do
62
+ `gem install pkg/#{PKG_FILE_NAME}.gem`
63
+ end
64
+
65
+ #-----------------------------------------------------------------------
66
+ # gem specification for :package
67
+ #-----------------------------------------------------------------------
68
+ task :package => [:clobber, :readme]
69
+
70
+ spec = Gem::Specification.new do |s|
71
+ s.name = PKG_NAME
72
+ s.version = PKG_VERSION
73
+ s.platform = Gem::Platform::RUBY
74
+ s.summary = "better living through metaprogramming:"
75
+ s.description = <<DESC
76
+ traits.rb aims to be a better set of attr_* methods and encourages
77
+ better living through meta-programming and uniform access priciples.
78
+ traits.rb supercedes attributes.rb. why? the name is shorter ;-)
79
+ DESC
80
+
81
+ s.has_rdoc = false
82
+
83
+ # no dependencies
84
+ # s.add_dependency('gem', '>= version')
85
+
86
+ s.files = %w(README VERSION) + Dir['lib/**/*'] + Dir['sample/**/*']
87
+ s.require_path = '.'
88
+
89
+ s.author = "Ara T. Howard"
90
+ s.email = "ara [dot] t [dot] howard [at] noaa [dot] gov"
91
+
92
+ end
93
+
94
+ Rake::GemPackageTask.new(spec) do |p|
95
+ p.gem_spec = spec
96
+ p.need_tar = true
97
+ p.need_zip = true
98
+ end