From 054be00221cab1bf7c2407be479c3423798874da Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sun, 21 Mar 2010 00:24:24 +0100 Subject: [PATCH] typos and a test-box --- VERSION | 2 +- bin/box.rb | 27 +++++++++++++++++++++++++++ lib/safebox/box.rb | 2 +- lib/safebox/safebox.rb | 42 ++++++++++++++++++++++-------------------- 4 files changed, 51 insertions(+), 22 deletions(-) create mode 100755 bin/box.rb diff --git a/VERSION b/VERSION index 77d6f4c..8acdd82 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.0 +0.0.1 diff --git a/bin/box.rb b/bin/box.rb new file mode 100755 index 0000000..670ee03 --- /dev/null +++ b/bin/box.rb @@ -0,0 +1,27 @@ +#!/usr/bin/ruby + +begin + require 'sbdb' +rescue LoadError + $stderr.puts "Install sbdb: gem install sbdb" + exit 1 +end +require 'safebox' + +_ = nil +Dir.mkdir 'logs' rescue Errno::EEXIST +SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs| + db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE] + db = Safebox::Persistent.new db, db.cursor + $stdout.print "(0)$ " + STDIN.each_with_index do |line, i| + ret = Safebox.run line, Safebox::Box, db, _ + if :value == ret.first + _ = ret.last + $stdout.puts "=> #{ret.last.inspect}" + else + $stdout.puts ret.last.inspect, ret.last.backtrace.map( &" %s".method( :%)) + end + $stdout.print "(#{i+1})$ " + end +end diff --git a/lib/safebox/box.rb b/lib/safebox/box.rb index 07a995e..77d8f0b 100644 --- a/lib/safebox/box.rb +++ b/lib/safebox/box.rb @@ -1,4 +1,4 @@ -require 'safebox/sanfeox' +require 'safebox/safebox' class Safebox::Box attr_reader :_, :db diff --git a/lib/safebox/safebox.rb b/lib/safebox/safebox.rb index 9e44083..b6efb34 100644 --- a/lib/safebox/safebox.rb +++ b/lib/safebox/safebox.rb @@ -1,25 +1,27 @@ module Safebox - def self.run *paras, &exe - exe = paras.shift unless exe - box = paras.shift || Class - Thread.new do - $SAFE = 4 - this = box.new *paras - begin - [:value, this.instance_eval( exe, "Safebox")] - rescue Object - [:exception, $!] - end - end.value - end - - def self.create_class *paras, &exe - exe = paras.shift unless exe - run Class, *paras do - eval exe - self + class <