class Safemode::Scope
Public Class Methods
new(delegate = nil, delegate_methods = [])
click to toggle source
# File lib/safemode/scope.rb, line 3 def initialize(delegate = nil, delegate_methods = []) @delegate = delegate @delegate_methods = delegate_methods @locals = {} end
Public Instance Methods
bind(instance_vars = {}, locals = {}, &block)
click to toggle source
# File lib/safemode/scope.rb, line 9 def bind(instance_vars = {}, locals = {}, &block) @locals = symbolize_keys(locals) # why can't I just pull them to local scope in the same way like instance_vars? instance_vars = symbolize_keys(instance_vars) instance_vars.each {|key, obj| eval "@#{key} = instance_vars[:#{key}]" } @_safemode_output = '' binding end
method_missing(method, *args, &block)
click to toggle source
# File lib/safemode/scope.rb, line 33 def method_missing(method, *args, &block) if @locals.has_key?(method) @locals[method] elsif @delegate_methods.include?(method) @delegate.send method, *unjail_args(args), &block else raise Safemode::SecurityError.new(method, "#<Safemode::ScopeObject>") end end
output()
click to toggle source
# File lib/safemode/scope.rb, line 29 def output @_safemode_output end
print(*args)
click to toggle source
# File lib/safemode/scope.rb, line 25 def print(*args) @_safemode_output += args.to_s end
puts(*args)
click to toggle source
# File lib/safemode/scope.rb, line 21 def puts(*args) print args.to_s + "\n" end
to_jail()
click to toggle source
# File lib/safemode/scope.rb, line 17 def to_jail self end
Private Instance Methods
symbolize_keys(hash)
click to toggle source
# File lib/safemode/scope.rb, line 45 def symbolize_keys(hash) hash.inject({}) do |hash, (key, value)| hash[key.to_s.intern] = value hash end end
unjail_args(args)
click to toggle source
# File lib/safemode/scope.rb, line 52 def unjail_args(args) args.collect do |arg| arg.class.name =~ /::Jail$/ ? arg.instance_variable_get(:@source) : arg end end