class GemBootstrap::FileConflictManager

@api private

Constants

PROMPT

Public Class Methods

new(io:) click to toggle source
# File lib/gem-bootstrap/file_conflict_manager.rb, line 11
def initialize(io:)
  @io = io
  @overwrite_all = false
end

Public Instance Methods

overwrite_all?() click to toggle source

@return [Boolean]

# File lib/gem-bootstrap/file_conflict_manager.rb, line 17
def overwrite_all?
  @overwrite_all
end
should_overwrite?(file_path, old_contents, new_contents) click to toggle source

@return [Boolean] Returns `true` if the file should be overwritten

# File lib/gem-bootstrap/file_conflict_manager.rb, line 22
def should_overwrite?(file_path, old_contents, new_contents)
  if @overwrite_all
    true
  else
    ask(file_path, old_contents, new_contents)
  end
end

Private Instance Methods

ask(path, old, new) click to toggle source
# File lib/gem-bootstrap/file_conflict_manager.rb, line 32
def ask(path, old, new)
  loop do
    case prompt(path).downcase.strip
    when 'y' then return true
    when 'n' then return false
    when 'a' then return @overwrite_all = true
    when 'q' then throw :exit, 0
    when 'd' then print_diff(old, new)
    else print_help
    end
  end
end
print_diff(left, right) click to toggle source
print_help() click to toggle source
prompt(file_path) click to toggle source
# File lib/gem-bootstrap/file_conflict_manager.rb, line 45
def prompt(file_path)
  @io.write(format(PROMPT, path: file_path))
  @io.readline.downcase.strip
end