module Get

File: get.rb Project: dotfiles-cli Author: exstnce (exstnce@protonmail.ch) Created on Sunday, 8th July 2018 5:53:22 pm

Public Class Methods

answer() click to toggle source
# File lib/dotfiles/utils/get.rb, line 45
def self.answer
  answer = STDIN.gets.chomp

  if answer.strip.downcase == 'y' || answer.strip == ''
    return true
  end
false
end
exists(name) click to toggle source
# File lib/dotfiles/utils/get.rb, line 36
def self.exists(name)
  path = path(name)
  unless File.exists?(path)
    puts "#{"Error".red}: #{name} does not exist"
    exit
  end
  path
end
name() click to toggle source
# File lib/dotfiles/utils/get.rb, line 26
def self.name
  print 'Save as: '
  @name = STDIN.gets.chomp.delete(' ')
  check
end
path(name) click to toggle source
# File lib/dotfiles/utils/get.rb, line 32
def self.path(name)
  @@dotfiles+name+'/'
end

Private Class Methods

check() click to toggle source
# File lib/dotfiles/utils/get.rb, line 56
def self.check
  if @name.empty?
    name
  end

  @path = @@dotfiles+@name+'/'

  if File.exists?(@path)
    puts "#{"Warn".yellow}: #{@name} already exists"
    puts
    puts ' (1) Delete the directory'
    puts
    puts ' (2) Select a different name'
    puts
    puts ' (3) Exit'
    puts
    print 'Please, choose the desired option (default=2): '
    option = STDIN.gets.chomp.strip

    case option
      when option.length > 1
        name
      when '1'
        FileUtils.rm_rf(@path)
      when '2'
        name
      when '3'
        exit
      else
        name
    end
  end
  @name
end