Class: TrustedSandbox::HostRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HostRunner.

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/host_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/host_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/host_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
# File 'lib/trusted_sandbox/host_runner.rb', line 17

def run(klass, *args)
  if config.shortcut
    shortcut(klass, *args)
  else
    run_in_container(klass, *args)
  end
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:



29
30
31
# File 'lib/trusted_sandbox/host_runner.rb', line 29

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:



36
37
38
# File 'lib/trusted_sandbox/host_runner.rb', line 36

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:



44
45
46
# File 'lib/trusted_sandbox/host_runner.rb', line 44

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