class Radon::Util

Public Class Methods

first_run() click to toggle source
# File lib/core/util.rb, line 6
def self.first_run
  return if (File.directory?(SETTINGS_DIR) && File.exist?(SETTINGS_FILE))
  puts "Performing first time setup..."
  
  # Make settings dir
  FileUtils.mkdir_p(SETTINGS_DIR)
  vprint("Creating #{SETTINGS_DIR}")

  puts "Welcome to radon! It looks like it's your first time running."
  email    = ask "  Email: "
  gh_uname = ask "  GitHub username: "

  data = {
    :email => email,
    :username => gh_uname
  }

  File.write(File.join(SETTINGS_DIR, 'settings.json'), JSON.pretty_generate(data))
  vprint "Writing settings to #{File.join(SETTINGS_DIR, 'settings.json')}"
end
get_email() click to toggle source
# File lib/core/util.rb, line 27
def self.get_email
  JSON.parse(File.read(SETTINGS_FILE))['email']
end
get_github_username() click to toggle source
# File lib/core/util.rb, line 31
def self.get_github_username
  JSON.parse(File.read(SETTINGS_FILE))['username']
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH.

which('ruby') #=> /usr/bin/ruby
# File lib/core/util.rb, line 38
def self.which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    }
  end
  return nil
end

Public Instance Methods

open_in_atom(path) click to toggle source
# File lib/core/util.rb, line 54
def open_in_atom(path)
  fail_with('`atom` program is not in $PATH') if Radon::Util.which('atom').nil?
  `cd #{path} && atom .`
end
open_in_editor(opts, path) click to toggle source
# File lib/core/util.rb, line 59
def open_in_editor(opts, path)
  open_in_vscode(path) if opts[:open_vscode]
rescue StandardError => e
  report_error_to_github(e)
end
open_in_vscode(path) click to toggle source
# File lib/core/util.rb, line 49
def open_in_vscode(path)
  fail_with('`code` program is not in $PATH') if Radon::Util.which('code').nil?
  `cd #{path} && code .`
end