Class: DatabasePatcher::Interface::STD

Inherits:
DatabasePatcher::Interface show all
Defined in:
lib/database_patcher/interface/std.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ STD

Returns a new instance of STD.



4
5
6
# File 'lib/database_patcher/interface/std.rb', line 4

def initialize(options = {})
  @force = !!options[:force]
end

Instance Method Details

#ask(question) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/database_patcher/interface/std.rb', line 8

def ask(question)
  return true if @force
  Timeout.timeout(15) do
    loop do
      $stdout.puts(question.to_s + ' ([y]es/[n]o)')
      case $stdin.gets.chomp.strip.downcase 
      when 'y', 'yes'
        return true
      when 'n', 'no'
        return false
      else
        $stdout.puts('invalid answer, please try again')
      end
    end
  end
end