Class: Reviewer::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/prompt.rb

Overview

Simple interactive prompt for yes/no questions. Wraps input/output streams for testability.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: $stdin, output: $stdout) ⇒ Prompt

Creates an interactive prompt for yes/no questions



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

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

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



7
8
9
# File 'lib/reviewer/prompt.rb', line 7

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/reviewer/prompt.rb', line 7

def output
  @output
end

Instance Method Details

#yes?(message) ⇒ Boolean

Asks a yes/no question and returns the boolean result. Returns false in non-interactive contexts (CI, pipes).



24
25
26
27
28
29
30
# File 'lib/reviewer/prompt.rb', line 24

def yes?(message)
  return false unless interactive?

  @output.print "#{message} (y/n) "
  response = @input.gets&.strip&.downcase
  response&.start_with?('y') || false
end