Module: ExecSandbox

Defined in:
lib/exec_sandbox.rb,
lib/exec_sandbox/spawn.rb,
lib/exec_sandbox/users.rb,
lib/exec_sandbox/wait4.rb,
lib/exec_sandbox/sandbox.rb

Overview

namespace

Defined Under Namespace

Modules: Spawn, Users, Wait4 Classes: Sandbox

Class Method Summary collapse

Class Method Details

.open(admin = Etc.getlogin) ⇒ Sandbox

Creates a sandbox.

The sandbox should be disposed of by calling ExecSandbox::Sandbox#close on it. This method is much less convenient than #use, so make sure you have a good reason to call it.

Parameters:

  • admin (String) (defaults to: Etc.getlogin)

    the name of a user who will be able to peek into the sandbox (optional)

Returns:

  • (Sandbox)

    the newly created sandbox



196
197
198
# File 'lib/exec_sandbox/sandbox.rb', line 196

def self.open(admin = Etc.getlogin)
  ExecSandbox::Sandbox.new admin
end

.use(admin = Etc.getlogin) {|sandbox| ... } ⇒ Object

Creates a sandbox, yields it, and destroys it.

Parameters:

  • admin (String) (defaults to: Etc.getlogin)

    the name of a user who will be able to peek into the sandbox (optional)

Yield Parameters:

  • sandbox (Sandbox)

    a Sandbox instance that will be automatically destroyed after the block returns

Returns:

  • the value returned from the block passed to this method



178
179
180
181
182
183
184
185
# File 'lib/exec_sandbox/sandbox.rb', line 178

def self.use(admin = Etc.getlogin, &block)
  sandbox = ExecSandbox::Sandbox.new admin
  begin
    return yield(sandbox)
  ensure
    sandbox.close
  end
end