Permalink
Browse files

initial add, db_open works

  • Loading branch information...
0 parents commit 960817671f02675ba878bda3a440cc38fc6ec99c @tenderlove committed Nov 4, 2010
Showing with 167 additions and 0 deletions.
  1. +23 −0 .autotest
  2. +6 −0 CHANGELOG.rdoc
  3. +7 −0 Manifest.txt
  4. +48 −0 README.rdoc
  5. +13 −0 Rakefile
  6. +11 −0 lib/orient.rb
  7. +51 −0 lib/orient/connections/binary.rb
  8. +8 −0 test/test_orient.rb
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2010-11-04
+
+* 1 major enhancement
+
+ * Birthday!
+
@@ -0,0 +1,7 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/orient
+lib/orient.rb
+test/test_orient.rb
@@ -0,0 +1,48 @@
+= orient
+
+* FIX (url)
+
+== DESCRIPTION:
+
+FIX (describe your package)
+
+== FEATURES/PROBLEMS:
+
+* FIX (list of features or problems)
+
+== SYNOPSIS:
+
+ FIX (code sample of usage)
+
+== REQUIREMENTS:
+
+* FIX (list of requirements)
+
+== INSTALL:
+
+* FIX (sudo gem install, anything else)
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2010 Aaron Patterson
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.spec 'orient' do
+ developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
+ self.readme_file = 'README.rdoc'
+ self.history_file = 'CHANGELOG.rdoc'
+ self.extra_rdoc_files = FileList['*.rdoc']
+end
+
+# vim: syntax=ruby
@@ -0,0 +1,11 @@
+require 'orient/connections/binary'
+
+module Orient
+ VERSION = '1.0.0'
+end
+
+if $0 == __FILE__
+ conn = Orient::Connections::Binary.new 'localhost'
+ clusters = conn.db_open 'local:demo', 'admin', 'admin'
+ conn.datacluster_count clusters.first
+end
@@ -0,0 +1,51 @@
+require 'socket'
+
+module Orient
+ class Cluster < Struct.new(:name, :id, :type)
+ end
+
+ module Connections
+ class Binary
+ def initialize remote_host, port = 2424, lhost = nil, lport = nil
+ @socket = TCPSocket.new remote_host, port, lhost, lport
+ @tx = 0
+ end
+
+ def datacluster_count cluster
+ end
+
+ def db_open db, user, pass
+ header = [
+ 5, # Operation: CONNECT
+ @tx, # TX ID
+ ]
+ header = header.pack('cN')
+ str = [
+ [ db.bytesize, db ],
+ [ user.bytesize, user ],
+ [ pass.bytesize, pass ]
+ ]
+ str = str.map { |tuple| [tuple.first].pack('N') + tuple.last }.join
+ @socket.write(header + str)
+ @tx += 1
+
+ response = @socket.read(1).unpack('c').first
+
+ raise unless response == 0
+
+ txid, connection_id, cluster_count = @socket.read(12).unpack('N3')
+
+ clusters = []
+ cluster_count.times do
+ len = @socket.read(4).unpack('N').first
+ cluster_name = @socket.read(len)
+ cluster_id, len = @socket.read(8).unpack('N2')
+ cluster_type = @socket.read(len)
+ clusters << Cluster.new(cluster_name, cluster_id, cluster_type)
+ end
+
+ clusters
+ end
+ end
+ end
+end
@@ -0,0 +1,8 @@
+require "test/unit"
+require "orient"
+
+class TestOrient < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end

0 comments on commit 9608176

Please sign in to comment.