Class: Retest::Prompt

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Prompt.



14
15
16
17
# File 'lib/retest/prompt.rb', line 14

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

Instance Attribute Details

#inputObject

Returns the value of attribute input.



13
14
15
# File 'lib/retest/prompt.rb', line 13

def input
  @input
end

#outputObject

Returns the value of attribute output.



13
14
15
# File 'lib/retest/prompt.rb', line 13

def output
  @output
end

Class Method Details

.ask_which_test_to_use(path, files) ⇒ Object



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

def self.ask_which_test_to_use(path, files)
  new.ask_which_test_to_use(path, files)
end

.puts(*args) ⇒ Object



9
10
11
# File 'lib/retest/prompt.rb', line 9

def self.puts(*args)
  new.puts(*args)
end

Instance Method Details

#ask_which_test_to_use(path, files) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/retest/prompt.rb', line 19

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.chomp.to_i]
end

#puts(*args) ⇒ Object



37
38
39
# File 'lib/retest/prompt.rb', line 37

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

#read_outputObject



41
42
43
# File 'lib/retest/prompt.rb', line 41

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