Module: Psychic::Runner::SampleRunner

Included in:
Psychic::Runner
Defined in:
lib/psychic/runner/sample_runner.rb

Instance Method Summary collapse

Instance Method Details

#find_sample(code_sample) ⇒ Object



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

def find_sample(code_sample)
  find_in_hints(code_sample) || Psychic::Util.find_file_by_alias(code_sample, cwd)
end

#interactive?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/psychic/runner/sample_runner.rb', line 40

def interactive?
  !@interactive_mode.nil?
end

#process_parameters(sample_file) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/psychic/runner/sample_runner.rb', line 24

def process_parameters(sample_file)
  if templated?
    backup_and_overwrite(sample_file)

    template = File.read(sample_file)
    # Default token pattern/replacement (used by php-opencloud) should be configurable
    token_handler = RegexpTokenHandler.new(template, /'\{(\w+)\}'/, "'\\1'")
    confirm_or_update_parameters(token_handler.tokens)
    File.write(sample_file, token_handler.render(@parameters))
  end
end

#run_sample(code_sample, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/psychic/runner/sample_runner.rb', line 8

def run_sample(code_sample, *args)
  sample_file = find_sample(code_sample)
  absolute_sample_file = File.expand_path(sample_file, cwd)
  process_parameters(absolute_sample_file)
  command = build_command(code_sample, sample_file)
  if command
    execute(command, *args)
  else
    run_sample_file(sample_file)
  end
end

#run_sample_file(sample_file, *args) ⇒ Object



20
21
22
# File 'lib/psychic/runner/sample_runner.rb', line 20

def run_sample_file(sample_file, *args)
  execute("./#{sample_file}", *args) # Assuming Bash, but should detect Windows and use PowerShell
end

#templated?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/psychic/runner/sample_runner.rb', line 36

def templated?
  @parameter_mode == 'tokens'
end