Class: TrustedSandbox::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/trusted_sandbox/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, uid_pool, config_override = {}) ⇒ Runner

Returns a new instance of Runner.

Parameters:

  • config (Config)
  • uid_pool (UidPool)
  • config_override (Hash) (defaults to: {})

    allows overriding configurations for a specific invocation



9
10
11
12
# File 'lib/trusted_sandbox/runner.rb', line 9

def initialize(config, uid_pool, config_override={})
  @config = config.override(config_override)
  @uid_pool = uid_pool
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/trusted_sandbox/runner.rb', line 4

def config
  @config
end

#uid_poolObject (readonly)

Returns the value of attribute uid_pool.



4
5
6
# File 'lib/trusted_sandbox/runner.rb', line 4

def uid_pool
  @uid_pool
end

Instance Method Details

#run(klass, *args) ⇒ Response

Parameters:

  • klass (Class)

    the class object that should be run

  • *args (Array)

    arguments to send to klass#initialize

Returns:



17
18
19
20
21
22
23
24
25
26
# File 'lib/trusted_sandbox/runner.rb', line 17

def run(klass, *args)
  create_code_dir
  serialize_request(klass, *args)
  create_container
  start_container
ensure
  release_uid
  remove_code_dir
  remove_container
end

#run!(klass, *args) ⇒ Object

Return value from the #eval method

Parameters:

  • klass (Class)

    the class object that should be run

  • *args (Array)

    arguments to send to klass#initialize

Returns:

  • (Object)

    return value from the #eval method

Raises:



32
33
34
# File 'lib/trusted_sandbox/runner.rb', line 32

def run!(klass, *args)
  run(klass, *args).output!
end

#run_code(code, args = {}) ⇒ Response

Parameters:

  • code (String)

    code to be evaluated

  • args (Hash) (defaults to: {})

    hash to send to GeneralPurpose

Returns:



39
40
41
# File 'lib/trusted_sandbox/runner.rb', line 39

def run_code(code, args={})
  run(GeneralPurpose, code, args)
end

#run_code!(code, args = {}) ⇒ Object

Return value from the #eval method

Parameters:

  • code (String)

    code to be evaluated

  • args (Hash) (defaults to: {})

    hash to send to GeneralPurpose

Returns:

  • (Object)

    return value from the #eval method

Raises:



47
48
49
# File 'lib/trusted_sandbox/runner.rb', line 47

def run_code!(code, args={})
  run!(GeneralPurpose, code, args)
end