typos and a test-box
This commit is contained in:
parent
d27b1b3852
commit
054be00221
27
bin/box.rb
Executable file
27
bin/box.rb
Executable file
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||
require 'safebox/sanfeox'
|
||||
require 'safebox/safebox'
|
||||
|
||||
class Safebox::Box
|
||||
attr_reader :_, :db
|
||||
|
|
|
@ -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 <<self
|
||||
def 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 create_class *paras, &exe
|
||||
exe = paras.shift unless exe
|
||||
self.run Class, *paras do
|
||||
eval exe
|
||||
self
|
||||
end
|
||||
end
|
||||
alias new_class create_class
|
||||
end
|
||||
alias new_class create_class
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue