Sha256: e6537607262b7f440fca9f61e272b2881b6c5c3ddad4246a96fa55a31882c2eb
Contents?: true
Size: 1.36 KB
Versions: 11
Compression:
Stored size: 1.36 KB
Contents
require 'rubygems' require 'ruby2ruby' begin require 'ruby_parser' # try to load RubyParser and use it if present rescue LoadError => e end # this doesn't work somehow. Maybe something changed inside # ParseTree or sexp_processor or so. # (the require itself works, but ParseTree doesn't play nice) # begin # require 'parse_tree' # rescue LoadError => e # end require 'safemode/core_ext' require 'safemode/blankslate' require 'safemode/exceptions' require 'safemode/jail' require 'safemode/core_jails' require 'safemode/parser' require 'safemode/scope' module Safemode class << self def jail(obj) find_jail_class(obj.class).new obj end def find_jail_class(klass) while klass != Object return klass.const_get('Jail') if klass.const_defined?('Jail') klass = klass.superclass end Jail end end define_core_jail_classes class Box def initialize(delegate = nil, delegate_methods = [], filename = nil, line = nil) @scope = Scope.new(delegate, delegate_methods) @filename = filename @line = line end def eval(code, assigns = {}, locals = {}, &block) code = Parser.jail(code) binding = @scope.bind(assigns, locals, &block) result = Kernel.eval(code, binding, @filename || __FILE__, @line || __LINE__) end def output @scope.output end end end
Version data entries
11 entries across 11 versions & 1 rubygems