Class: Rubikon::Application::Sandbox
- Defined in:
- lib/rubikon/application/sandbox.rb
Overview
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.
Instance Method Summary collapse
-
#initialize(app) ⇒ Sandbox
constructor
Create a new application sandbox.
-
#method_missing(name, *args, &block) ⇒ Object
Method calls on the sandbox wrapper will be relayed to the singleton instance.
-
#putc(text) ⇒ Object
Relay putc to the instance method.
-
#puts(text = nil) ⇒ Object
Relay puts to the instance method.
Constructor Details
#initialize(app) ⇒ Sandbox
Create a new application sandbox
24 25 26 27 |
# File 'lib/rubikon/application/sandbox.rb', line 24 def initialize(app) raise ArgumentError unless app.is_a? Application::Base @__app__ = app end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Method calls on the sandbox wrapper will be relayed to the singleton instance. Methods defined in InstanceMethods are protected and will raise a NoMethodError.
37 38 39 40 41 42 43 44 45 |
# 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 |
Instance Method Details
#putc(text) ⇒ Object
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
54 55 56 |
# File 'lib/rubikon/application/sandbox.rb', line 54 def putc(text) @__app__.send(:putc, text) end |
#puts(text = nil) ⇒ Object
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
64 65 66 |
# File 'lib/rubikon/application/sandbox.rb', line 64 def puts(text = nil) @__app__.send(:puts, text) end |