Skip to content

Commit

Permalink
add basic sink operation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgrana committed Apr 24, 2011
1 parent 30bae7e commit 91f0396
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions lib/gorg.rb
Expand Up @@ -13,6 +13,10 @@ def initialize(opts)
@path = opts[:path]
end

def write(file, r)
file.puts(JSON.dump({"path" => r.path, "value" => r.value, "rev" => r.rev}))

This comment has been minimized.

Copy link
@kr

kr Apr 24, 2011

This doesn't distinguish between emptying a file and deleting it.
You can use r.set? to tell the difference.

end

def dump
log("dump event=open")
file = @path ? File.open(@path, "w") : $stdout
Expand All @@ -23,7 +27,7 @@ def dump
log("dump event=req")
client.walk(nil, "/**") do |r|
log("dump event=res path=#{r.path}")
file.puts(JSON.dump({"path" => r.path, "value" => r.value, "rev" => r.rev}))
write(file, r)
end.done do
log("dump event=stop")
EM.stop
Expand All @@ -34,6 +38,31 @@ def dump
end
end

def sink
log("sink event=open")
file = @path ? File.open(@path, "w") : $stdout
log("sink event=run")
EM.run do
log("sink event=connect")
client = Fraggle.connect
log("sink event=rev")
client.rev do |r|
rev = r.rev
log("sink event=walk rev=#{rev}")
client.walk(rev, "/**") do |r|
log("sink event=res path=#{r.path}")
write(file, r)
end.done do
log("sink event=watch rev=#{rev+1}")
client.watch(rev+1, "/**") do |r|
log("sink event=res path=#{r.path}")
write(file, r)
end
end
end
end
end

def load
log("load event=open")
file = @path ? File.open(@path, "r") : $stdin
Expand Down Expand Up @@ -65,10 +94,6 @@ def load
end
end

def sink
raise("sink'ing, how does it work?")
end

def log(msg)
$stderr.puts("gorg #{msg}") if @log
end
Expand Down

0 comments on commit 91f0396

Please sign in to comment.