Class: Timmy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/timmy/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(replay_speed:) ⇒ Runner

Returns a new instance of Runner.



27
28
29
30
# File 'lib/timmy/runner.rb', line 27

def initialize(replay_speed:)
  @replay_speed = replay_speed
  @last_replay_time = 0
end

Class Method Details

.runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/timmy/runner.rb', line 8

def run
  ConfigLoader.load

  options = OptionParser.parse
  replay_speed = options[:replay_speed] || @replay_speed
  Logger.set_quiet(options[:quiet]) if options.key?(:quiet)
  Logger.set_precision(options[:precision]) if options.key?(:precision)
  Logger.set_profile(options[:profile]) if options.key?(:profile)

  instance = self.new(replay_speed: replay_speed)

  if command = options[:command]
    instance.stream_command(command)
  else
    instance.consume_stdin()
  end
end

.set_replay_speed(speed) ⇒ Object



4
5
6
# File 'lib/timmy/runner.rb', line 4

def set_replay_speed(speed)
  @replay_speed = speed
end

Instance Method Details

#consume_stdinObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/timmy/runner.rb', line 40

def consume_stdin
  around_run_lines do
    STDIN.each_line do |line|
      next if init_replay_mode(line)

      if @replay_mode
        replay_line(line)
      else
        run_line(line.rstrip)
      end
    end
  end
end

#stream_command(command) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/timmy/runner.rb', line 32

def stream_command(command)
  around_run_lines do
    CommandStreamer.stream(command) do |type, line|
      run_line(line.rstrip, type)
    end
  end
end