Class: RakeCommit::PromptLine

Inherits:
Object
  • Object
show all
Includes:
Readline
Defined in:
lib/rake_commit/prompt_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute, prompt_exclusions = [], default_value = nil) ⇒ PromptLine

Returns a new instance of PromptLine.



8
9
10
11
12
# File 'lib/rake_commit/prompt_line.rb', line 8

def initialize(attribute, prompt_exclusions = [], default_value = nil)
  @attribute = attribute
  @prompt_exclusions = prompt_exclusions
  @default_value = default_value
end

Instance Method Details

#promptObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rake_commit/prompt_line.rb', line 14

def prompt
  return nil if @prompt_exclusions.include?(@attribute)

  puts "\n"
  puts "previous #{@attribute}: #{previous_input}" if previous_input

  set_readline_default_input(@default_value) if @default_value
  set_readline_history

  input = nil
  loop do
    input = readline("#{@attribute}: ").chomp
    break unless (input.empty? && !previous_input)
  end

  unless input.empty?
    append_history(input)
    return input
  end

  puts "using: #{previous_input}"
  return previous_input
end