class Rubikon::Application::Sandbox

The application sandbox is a wrapper used to secure internal Rubikon logic from access by user generated application code.

This is mostly to prevent accidental execution or change of Rubikon’s internal code. But it also helps to prevent possible security problems depending on the code used inside the application logic.

@see Application::InstanceMethods @since 0.4.0

Public Class Methods

new(app) click to toggle source

Create a new application sandbox

@param [Application::Base] app The application to be sandboxed

# File lib/rubikon/application/sandbox.rb, line 24
def initialize(app)
  raise ArgumentError unless app.is_a? Application::Base
  @__app__ = app
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source

Method calls on the sandbox wrapper will be relayed to the singleton instance. Methods defined in InstanceMethods are protected and will raise a NoMethodError.

@param (see ClassMethods#method_missing) @raise [NoMethodError] if a method is called that is defined inside

InstanceMethods and should therefore be protected

@see InstanceMethods

# File lib/rubikon/application/sandbox.rb, line 37
def method_missing(name, *args, &block)
  if @__app__.class.instance_methods(false).include?(name.to_s) ||
     !(InstanceMethods.method_defined?(name) ||
     InstanceMethods.private_method_defined?(name))
    @__app__.send(name, *args, &block)
  else
    raise NoMethodError.new("Method `#{name}' is protected by the application sandbox", name)
  end
end
putc(text) click to toggle source

Relay putc to the instance method

This is used to hide Kernel#putc so that the application’s output IO object is used for printing characters

@param [String, Numeric] char The character to write into the output

stream
# File lib/rubikon/application/sandbox.rb, line 54
def putc(text)
  @__app__.send(:putc, text)
end
puts(text = nil) click to toggle source

Relay puts to the instance method

This is used to hide Kernel#puts so that the application’s output IO object is used for printing text

@param [String] text The text to write into the output stream

# File lib/rubikon/application/sandbox.rb, line 64
def puts(text = nil)
  @__app__.send(:puts, text)
end