Class: Psychic::Runner::CodeSample

Inherits:
Struct
  • Object
show all
Includes:
OutputHelper, CodeHelper
Defined in:
lib/psychic/runner/code_sample.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OutputHelper

#build_string, #cli, #color_pad, #colorize, #indent, #print_table, #reformat, #say, #status

Methods included from CodeHelper

#absolute_source_file, #code_block, #detect_language, #highlighted_code, #language, #source, #source?

Instance Attribute Details

#basedirObject

Returns the value of attribute basedir

Returns:

  • (Object)

    the current value of basedir



5
6
7
# File 'lib/psychic/runner/code_sample.rb', line 5

def basedir
  @basedir
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/psychic/runner/code_sample.rb', line 5

def name
  @name
end

#source_fileObject

Returns the value of attribute source_file

Returns:

  • (Object)

    the current value of source_file



5
6
7
# File 'lib/psychic/runner/code_sample.rb', line 5

def source_file
  @source_file
end

Instance Method Details

#command(runner) ⇒ Object



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

def command(runner)
  command = runner.task_for(:run_sample)
  # FIXME: Shouldn't this be relative to runner's cwd?
  # command ||= Psychic::Util.relativize(source_file, runner.cwd)
  command ||= "./#{source_file}"

  command_params = { sample: name, sample_file: source_file }
  command_params.merge!(@parameters) unless @parameters.nil?
  Psychic::Util.replace_tokens(command, command_params)
end

#to_pathObject



37
38
39
40
# File 'lib/psychic/runner/code_sample.rb', line 37

def to_path
  # So coercion to Pathname is possible
  source_file.to_s
end

#to_s(verbose = false) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/psychic/runner/code_sample.rb', line 28

def to_s(verbose = false)
  build_string do
    status('Sample Name', name)
    display_tokens
    status('Source File', formatted_file_name)
    display_source if verbose
  end
end

#token_handlerObject

property :name property :basedir property :source_file



12
13
14
15
# File 'lib/psychic/runner/code_sample.rb', line 12

def token_handler
  # Default token pattern/replacement (used by php-opencloud) should be configurable
  @token_handler ||= RegexpTokenHandler.new(source, /'\{(\w+)\}'/, "'\\1'")
end