Class: Polytrix::ChallengeRunner

Inherits:
Thor::Shell::Color
  • Object
show all
Includes:
Executor, Util::FileSystem
Defined in:
lib/polytrix/challenge_runner.rb

Instance Attribute Summary

Attributes included from Executor

#env, #executor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Executor

#execute

Methods included from Util::FileSystem

#find_file, #relativize

Methods included from Util::String

included

Methods included from Util::String::ClassMethods

#ansi2html, #escape_html, #highlight, #slugify

Class Method Details

.create_runnerObject



14
15
16
17
18
19
20
21
22
# File 'lib/polytrix/challenge_runner.rb', line 14

def self.create_runner
  case RbConfig::CONFIG['host_os']
  when /mswin(\d+)|mingw/i
    # TODO: Display warning that Windows support is experimental
    Executors::WindowsChallengeRunner.new
  else
    Executors::LinuxChallengeRunner.new
  end
end

Instance Method Details

#run_challenge(challenge, spies = Polytrix::Spies) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/polytrix/challenge_runner.rb', line 33

def run_challenge(challenge, spies = Polytrix::Spies)
  source_file = challenge[:source_file].to_s
  basedir = challenge[:basedir].to_s
  command = challenge_command(source_file, basedir)
  spies.observe(challenge) do
    execution_result = run_command(command, cwd: basedir, env: environment_variables(challenge[:vars]))
    challenge[:result] = Result.new(execution_result: execution_result, source_file: source_file)
  end
  challenge[:result]
end

#run_command(command, opts = { cwd: Dir.pwd }) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/polytrix/challenge_runner.rb', line 24

def run_command(command, opts = { cwd: Dir.pwd })
  if Polytrix.configuration.dry_run
    puts "Would have run #{command} with #{opts.inspect}"
  else
    say_status 'polytrix:execute', command
    execute(command, opts)
  end
end