module Abt::Helpers

Public Class Methods

command_to_const(string) click to toggle source
# File lib/abt/helpers.rb, line 12
def command_to_const(string)
  inflector = Dry::Inflector.new
  inflector.camelize(inflector.underscore(string))
end
const_to_command(string) click to toggle source
# File lib/abt/helpers.rb, line 6
def const_to_command(string)
  string = string.to_s.dup
  string[0] = string[0].downcase
  string.gsub(/([A-Z])/, '-\1').downcase
end
read_user_input() click to toggle source
# File lib/abt/helpers.rb, line 17
def read_user_input
  open(tty_path, &:gets).strip # rubocop:disable Security/Open
end

Private Class Methods

tty_path() click to toggle source
# File lib/abt/helpers.rb, line 23
def tty_path
  @tty_path ||= begin
    candidates = ["/dev/tty", "CON:"] # Unix: '/dev/tty', Windows: 'CON:'
    selected = candidates.find { |candidate| File.exist?(candidate) }
    raise Abort, "Unable to prompt for user input" if selected.nil?

    selected
  end
end