Class: Psychic::Runner::CodeSample
- Inherits:
-
Struct
- Object
- Struct
- Psychic::Runner::CodeSample
- Includes:
- OutputHelper, CodeHelper
- Defined in:
- lib/psychic/runner/code_sample.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
Returns the value of attribute basedir.
-
#name ⇒ Object
Returns the value of attribute name.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
Instance Method Summary collapse
- #command(runner) ⇒ Object
- #to_path ⇒ Object
- #to_s(verbose = false) ⇒ Object
-
#token_handler ⇒ Object
property :name property :basedir property :source_file.
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
#basedir ⇒ Object
Returns the value of attribute basedir
5 6 7 |
# File 'lib/psychic/runner/code_sample.rb', line 5 def basedir @basedir end |
#name ⇒ Object
Returns the value of attribute name
5 6 7 |
# File 'lib/psychic/runner/code_sample.rb', line 5 def name @name end |
#source_file ⇒ Object
Returns the value of attribute 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_path ⇒ Object
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_handler ⇒ Object
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 |