Class: Metro::SetupHandlers::GameExecution

Inherits:
Object
  • Object
show all
Defined in:
lib/setup_handlers/game_execution.rb

Overview

The GameExecution allows for a game to be executed. This is used by Metro to validate that the code can be loaded and run before actually running it (specifically when reloading live running code)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ GameExecution

Returns a new instance of GameExecution.

Parameters:

  • parameters (Array)

    an array of the game parameters that are to be provided to this execution of the game.



32
33
34
# File 'lib/setup_handlers/game_execution.rb', line 32

def initialize(parameters)
  @parameters = parameters
end

Instance Attribute Details

#outputObject (readonly)

Returns the output generated from the execution of code.

Returns:

  • the output generated from the execution of code.



22
23
24
# File 'lib/setup_handlers/game_execution.rb', line 22

def output
  @output
end

#parametersObject (readonly)

Returns an array of parameters that will be provided to the execution of the game.

Returns:

  • an array of parameters that will be provided to the execution of the game.



26
27
28
# File 'lib/setup_handlers/game_execution.rb', line 26

def parameters
  @parameters
end

Class Method Details

.execute(parameters) ⇒ Object

Perform a game execution with the specified parameters and return the result of that game execution.



15
16
17
18
19
# File 'lib/setup_handlers/game_execution.rb', line 15

def self.execute(parameters)
  execution = new(parameters)
  execution.execute!
  execution
end

Instance Method Details

#execute!Object

Perform the game execution.



43
44
45
# File 'lib/setup_handlers/game_execution.rb', line 43

def execute!
  @output, @status = Open3.capture2e(game_execution_string)
end

#invalid?TrueClass, FalseClass

Returns true if the execution was a failure.

Returns:

  • (TrueClass, FalseClass)

    true if the execution was a failure.



53
54
55
# File 'lib/setup_handlers/game_execution.rb', line 53

def invalid?
  status != 0
end

#statusObject

Returns the status code that was returned when the game execution has completed.

Returns:

  • the status code that was returned when the game execution has completed.



38
39
40
# File 'lib/setup_handlers/game_execution.rb', line 38

def status
  @status ||= 0
end

#valid?TrueClass, FalseClass

Returns true if the execution was successful.

Returns:

  • (TrueClass, FalseClass)

    true if the execution was successful.



48
49
50
# File 'lib/setup_handlers/game_execution.rb', line 48

def valid?
  status == 0
end