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)
  @sample_finder.find_sample(code_sample)
end

#interactive?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/psychic/runner/sample_runner.rb', line 31

def interactive?
  !@interactive_mode.nil?
end

#process_parameters(sample_file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/psychic/runner/sample_runner.rb', line 15

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_name, *args) ⇒ Object



8
9
10
11
12
13
# File 'lib/psychic/runner/sample_runner.rb', line 8

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)
  execute(code_sample.command(self), *args)
end

#templated?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/psychic/runner/sample_runner.rb', line 27

def templated?
  @parameter_mode == 'tokens'
end