Class: Retest::Prompt

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/retest/prompt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: nil, output: nil) ⇒ Prompt

Returns a new instance of Prompt.



6
7
8
9
10
# File 'lib/retest/prompt.rb', line 6

def initialize(input: nil, output: nil)
  @input  = input || $stdin
  @output = output || $stdout
  @question_asked = false
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



5
6
7
# File 'lib/retest/prompt.rb', line 5

def input
  @input
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/retest/prompt.rb', line 5

def output
  @output
end

Instance Method Details

#ask_which_test_to_use(path, files) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/retest/prompt.rb', line 12

def ask_which_test_to_use(path, files)
  changed
  notify_observers(:question)
  options = options(files)

  output.puts(<<~QUESTION)
    We found few tests matching: #{path}

    #{list_options(options.keys)}

    Which file do you want to use?
    Enter the file number now:
  QUESTION
  output.print("> ")
  options.values[input.gets.to_s.chomp.to_i]
end

#puts(*args) ⇒ Object



29
30
31
# File 'lib/retest/prompt.rb', line 29

def puts(*args)
  output.puts(*args)
end

#read_outputObject



33
34
35
# File 'lib/retest/prompt.rb', line 33

def read_output
  output.tap(&:rewind).read
end