Module: Kettle::Dev::InputAdapter

Defined in:
lib/kettle/dev/input_adapter.rb

Overview

Input indirection layer to make interactive prompts safe in tests.

Production/default behavior delegates to $stdin.gets (or Kernel#gets)
so application code does not read from STDIN directly. In specs, mock
this adapter’s methods to return deterministic answers without touching
global IO.

Example (RSpec):
allow(Kettle::Dev::InputAdapter).to receive(:gets).and_return(“y\n”)

This mirrors the “mockable adapter” approach used for GitAdapter and ExitAdapter.

Class Method Summary collapse

Class Method Details

.gets(*args) ⇒ String?

Read one line from the standard input, including the trailing newline if
present. Returns nil on EOF, consistent with IO#gets.

Parameters:

  • args (Array)

    any args are forwarded to $stdin.gets for compatibility

Returns:

  • (String, nil)


24
25
26
# File 'lib/kettle/dev/input_adapter.rb', line 24

def gets(*args)
  $stdin.gets(*args)
end

.readline(*args) ⇒ String

Read one line from standard input, raising EOFError on end-of-file.
Provided for convenience symmetry with IO#readline when needed.

Parameters:

  • args (Array)

Returns:

  • (String)

Raises:

  • (EOFError)


37
38
39
40
41
# File 'lib/kettle/dev/input_adapter.rb', line 37

def readline(*args)
  line = gets(*args)
  raise EOFError, "end of file reached" if line.nil?
  line
end

.tty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/kettle/dev/input_adapter.rb', line 28

def tty?
  $stdin.tty?
end