Class: InfinityTest::Command

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Command

Create new Command object that receive the ruby_version and the command string



7
8
9
10
11
12
13
# File 'lib/infinity_test/command.rb', line 7

def initialize(options={})
  @command = options[:command]
  @ruby_version = options[:ruby_version]
  @current_ruby_string = RVM::Environment.current_ruby_string
  @results = []
  @line = []
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

#resultsObject

Returns the value of attribute results.



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

def results
  @results
end

#ruby_versionObject

Returns the value of attribute ruby_version.



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

def ruby_version
  @ruby_version
end

Instance Method Details

#push_in_the_results(test_line) ⇒ Object

Push in the results the test line If have in the Ruby Enterpise Edition or Ruby 1.8.* pack the numbers returned. Join otherwise.



44
45
46
47
48
49
# File 'lib/infinity_test/command.rb', line 44

def push_in_the_results(test_line)
  if test_line == ?\n
    @results.push(yarv? ? @line.join : @line.pack('c*'))
    @line.clear
  end
end

#run!Object

Code taken in Autotest gem and change a little



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/infinity_test/command.rb', line 17

def run!
  old_sync = $stdout.sync
  $stdout.sync = true      
  begin
    open("| #{@command}", "r") do |file|
      until file.eof? do
        test_line = file.getc or break
        if yarv?
          print(test_line)
        else
          putc(test_line)
        end
        @line.push(test_line)
        push_in_the_results(test_line)
      end
    end
  ensure
    $stdout.sync = old_sync      
  end
  @results = @results.join
  self
end

#yarv?Boolean

Using yarv?

Returns:

  • (Boolean)


53
54
55
# File 'lib/infinity_test/command.rb', line 53

def yarv?
  @current_ruby_string =~ /ruby-1.9/
end