class Safemode::Jail
Public Class Methods
new(source = nil)
click to toggle source
# File lib/safemode/jail.rb, line 3 def initialize(source = nil) @source = source end
Public Instance Methods
method_missing(method, *args, **kwargs, &block)
click to toggle source
# File lib/safemode/jail.rb, line 15 def method_missing(method, *args, **kwargs, &block) if @source.is_a?(Class) unless self.class.allowed_class_method?(method) raise Safemode::NoMethodError.new(".#{method}", self.class.name, @source.name) end else unless self.class.allowed_instance_method?(method) raise Safemode::NoMethodError.new("##{method}", self.class.name, @source.class.name) end end # As every call to an object in the eval'ed string will be jailed by the # parser we don't need to "proactively" jail arrays and hashes. Likewise we # don't need to jail objects returned from a jail. Doing so would provide # "double" protection, but it also would break using a return value in an if # statement, passing them to a Rails helper etc. @source.send(method, *args, **kwargs, &block) end
respond_to_missing?(method_name, include_private = false)
click to toggle source
# File lib/safemode/jail.rb, line 34 def respond_to_missing?(method_name, include_private = false) self.class.allowed_instance_method?(method_name) end
to_jail()
click to toggle source
# File lib/safemode/jail.rb, line 7 def to_jail self end
to_s()
click to toggle source
# File lib/safemode/jail.rb, line 11 def to_s @source.to_s end