Browse files

project stub with basic rev infrastructure

  • Loading branch information...
0 parents commit d9aaaebd1ffc3325bf4450745e68f1ff29d9176b @substack committed Oct 3, 2010
Showing with 49 additions and 0 deletions.
  1. +3 −0 README.md
  2. +24 −0 dnode.rb
  3. +17 −0 dnode/conn.rb
  4. +3 −0 dnode/scrub.rb
  5. +2 −0 dnode/walk.rb
3 README.md
@@ -0,0 +1,3 @@
+Implements the DNode protocol for ruby.
+
+See the [node.js dnode project](http://github.com/substack/dnode) for more info.
24 dnode.rb
@@ -0,0 +1,24 @@
+require './dnode/conn.rb'
+require 'rev'
+
+class DNode
+ def initialize obj={}
+ @object = obj
+ end
+
+ def connect *args, &block
+ types = args.inject({}) { |acc,x| acc.merge(x.class.to_s => x) }
+ host = types['String'] || 'localhost'
+ port = types['Fixnum']
+
+ event_loop = Rev::Loop.default
+ Conn.connect(host, port).attach(event_loop)
+ event_loop.run
+ end
+
+ def listen
+ event_loop = Rev::Loop.default
+ Rev::TCPServer.new(host, port, Conn).attach(event_loop)
+ event_loop.run
+ end
+end
17 dnode/conn.rb
@@ -0,0 +1,17 @@
+require 'rev'
+require 'events'
+
+class Conn < Rev::TCPSocket
+ include Events::Emitter
+
+ def on_connect
+ puts 'connect!'
+ end
+
+ def on_close
+ end
+
+ def on_read data
+ puts "data = #{data}"
+ end
+end
3 dnode/scrub.rb
@@ -0,0 +1,3 @@
+class Scrub
+
+end
2 dnode/walk.rb
@@ -0,0 +1,2 @@
+class Walk
+end

0 comments on commit d9aaaeb

Please sign in to comment.