lib/psychic/runner/sample_runner.rb in psychic-runner-0.0.7 vs lib/psychic/runner/sample_runner.rb in psychic-runner-0.0.8
- old
+ new
@@ -1,28 +1,19 @@
module Psychic
class Runner
module SampleRunner
def find_sample(code_sample)
- find_in_hints(code_sample) || Psychic::Util.find_file_by_alias(code_sample, cwd)
+ @sample_finder.find_sample(code_sample)
end
- def run_sample(code_sample, *args)
- sample_file = find_sample(code_sample)
- absolute_sample_file = File.expand_path(sample_file, cwd)
+ def run_sample(code_sample_name, *args)
+ code_sample = find_sample(code_sample_name)
+ absolute_sample_file = code_sample.absolute_source_file
process_parameters(absolute_sample_file)
- command = build_command(code_sample, sample_file)
- if command
- execute(command, *args)
- else
- run_sample_file(sample_file)
- end
+ execute(code_sample.command(self), *args)
end
- def run_sample_file(sample_file, *args)
- execute("./#{sample_file}", *args) # Assuming Bash, but should detect Windows and use PowerShell
- end
-
def process_parameters(sample_file)
if templated?
backup_and_overwrite(sample_file)
template = File.read(sample_file)
@@ -50,11 +41,11 @@
end
nil
end
def build_command(code_sample, sample_file)
- command = command_for_task('run_sample')
+ command = task_for(:run_sample)
return nil if command.nil?
command_params = { sample: code_sample, sample_file: sample_file }
command_params.merge!(@parameters) unless @parameters.nil?
Psychic::Util.replace_tokens(command, command_params)
@@ -78,9 +69,10 @@
@cli.yes? "Would you like to #{file} to #{orig} before running the sample?"
end
end
def prompt(key)
+ value = @parameters[key]
if value
return value unless @interactive_mode == 'always'
new_value = @cli.ask "Please set a value for #{key} (or enter to confirm #{value.inspect}): "
new_value.empty? ? value : new_value
else