Class: HTAuth::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/htauth/console.rb

Overview

Internal: Utility class for managing console input/output

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout) ⇒ Console

Returns a new instance of Console.



13
14
15
16
# File 'lib/htauth/console.rb', line 13

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

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



11
12
13
# File 'lib/htauth/console.rb', line 11

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



11
12
13
# File 'lib/htauth/console.rb', line 11

def output
  @output
end

Instance Method Details

#ask(prompt) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/htauth/console.rb', line 22

def ask(prompt)
  output.print prompt
  answer = read_answer
  output.puts
  raise ConsoleError, "No input given" if answer.nil?

  answer.strip!
  raise ConsoleError, "No input given" if answer.empty?

  answer
end

#read_answerObject



34
35
36
# File 'lib/htauth/console.rb', line 34

def read_answer
  input.noecho(&:gets)
end

#say(msg) ⇒ Object



18
19
20
# File 'lib/htauth/console.rb', line 18

def say(msg)
  @output.puts msg
end