Permalink
Browse files

update samples for rubygems

  • Loading branch information...
fizx committed Sep 18, 2009
1 parent b8b78a4 commit 42fbf5379d00f4af29fd99c56e79c2eebfd4caaf
Showing with 27 additions and 11 deletions.
  1. +11 −5 sample/demo.rb
  2. +1 −0 sample/dictfs.rb
  3. +6 −0 sample/hello.rb
  4. +1 −2 sample/openurifs.rb
  5. +8 −4 sample/yamlfs.rb
View
@@ -4,10 +4,10 @@
root = MetaDir.new
-if (ARGV.size != 1)
- puts "Usage: #{$0} <directory>"
- exit
-end
+# if (ARGV.size != 1)
+# puts "Usage: #{$0} <directory>"
+# exit
+# end
dirname = ARGV.shift
@@ -56,6 +56,9 @@ def to_s
@counter += 1
@counter.to_s + "\n"
end
+ def size
+ @counter.to_s.size
+ end
end
class Randwords
@@ -65,6 +68,9 @@ def initialize(*ary)
def to_s
@ary[rand(@ary.size)].to_s + "\n"
end
+ def size
+ @size ||= @ary.map{|v| v.size}.max
+ end
end
root.write_to('/hello',"Hello, World!\n")
@@ -89,6 +95,6 @@ def to_s
# Set the root FuseFS
FuseFS.set_root(root)
-FuseFS.mount_under(dirname)
+FuseFS.mount_under(dirname, 'nolocalcaches', *ARGV)
FuseFS.run # This doesn't return until we're unmounted.
View
@@ -1,5 +1,6 @@
# dictfs.rb
#
+
require "rubygems"
require 'fusefs'
include FuseFS
View
@@ -5,12 +5,18 @@ class HelloDir
def contents(path)
['hello.txt']
end
+
def file?(path)
path == '/hello.txt'
end
+
def read_file(path)
"Hello, World!\n"
end
+
+ def size(path)
+ read_file(path).size
+ end
end
hellodir = HelloDir.new
View
@@ -20,8 +20,7 @@ def directory?(path)
! (fn =~ /\./) # Does the last item doesn't contain a '.' ?
end
def file?(path)
- uri = scan_path(path)
- uri.pop =~ /\./ # Does the last item contain a '.' ?
+ !directory?(path)
end
def read_file(path)
proto, rest = split_path(path)
View
@@ -54,6 +54,10 @@ def read_file(path)
end
node.to_s
end
+
+ def size(path)
+ read_file(path).size
+ end
# File writing
def can_write?(path)
@@ -141,12 +145,12 @@ def rmdir(path)
end
if (File.basename($0) == File.basename(__FILE__))
- if (ARGV.size != 2)
- puts "Usage: #{$0} <directory> <yamlfile>"
+ if (ARGV.size < 2)
+ puts "Usage: #{$0} <directory> <yamlfile> <options>"
exit
end
- dirname, yamlfile = ARGV
+ dirname, yamlfile = ARGV.shift, ARGV.shift
unless File.directory?(dirname)
puts "Usage: #{dirname} is not a directory."
@@ -158,7 +162,7 @@ def rmdir(path)
# Set the root FuseFS
FuseFS.set_root(root)
- FuseFS.mount_under(dirname)
+ FuseFS.mount_under(dirname, *ARGV)
FuseFS.run # This doesn't return until we're unmounted.
end

0 comments on commit 42fbf53

Please sign in to comment.