Class: Splot::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/splot/command.rb

Direct Known Subclasses

CucumberCommand, RSpecCommand, TestUnitCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
# File 'lib/splot/command.rb', line 5

def initialize(params = {})
  @file         = params.fetch(:file).to_str
  @include_path = params[:include_path]
  @line_no      = Integer(params[:line]) if params.has_key? :line
  @preloader    = params[:preloader].to_str if params.has_key? :preloader
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/splot/command.rb', line 3

def file
  @file
end

#include_pathObject (readonly)

Returns the value of attribute include_path.



3
4
5
# File 'lib/splot/command.rb', line 3

def include_path
  @include_path
end

#line_noObject (readonly)

Returns the value of attribute line_no.



3
4
5
# File 'lib/splot/command.rb', line 3

def line_no
  @line_no
end

#preloaderObject (readonly)

Returns the value of attribute preloader.



3
4
5
# File 'lib/splot/command.rb', line 3

def preloader
  @preloader
end

Class Method Details

.for(file) ⇒ Object



12
13
14
15
16
17
# File 'lib/splot/command.rb', line 12

def self.for(file)
  ObjectSpace.each_object(Class).select { |klass| klass < self }.each do |subklass|
    return subklass if subklass.match? file
  end
  self
end

.match?(file) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/splot/command.rb', line 19

def self.match?(file)
  false
end

Instance Method Details

#commandObject



23
24
25
26
27
28
29
30
31
# File 'lib/splot/command.rb', line 23

def command
  [
    preloader,    # "spring"
    runner,       # "rake test"
    include_args, # "-Itest"
    file_arg,     # "TEST=\"/path/to/test.rb\""
    line_no_arg,  # "TESTOPTS=\"-n test_foo\""
  ].compact * ' '
end

#file_argObject



33
34
35
# File 'lib/splot/command.rb', line 33

def file_arg
  file
end

#include_argsObject



37
38
39
# File 'lib/splot/command.rb', line 37

def include_args
  include_path ? "-I#{include_path}" : nil
end

#line_no_argObject



41
42
43
# File 'lib/splot/command.rb', line 41

def line_no_arg
  line_no ? "-l #{line_no}" : nil
end

#runnerObject



45
46
47
# File 'lib/splot/command.rb', line 45

def runner
  raise RunnerNotFoundError, "cannot determine runner for #{file.inspect}"
end