module Kernel

Public Instance Methods

exit_msg(*msg) click to toggle source
# File lib/lessons_indexer/addons/utils.rb, line 17
def exit_msg(*msg)
  abort "[ERROR] #{msg.join(' ')}".red
end
warning(*msg) click to toggle source
# File lib/lessons_indexer/addons/utils.rb, line 13
def warning(*msg)
  warn "[WARNING] #{msg.join(' ')}".cyan
end
with_messages(prior = '', after = '', delimiter = true, output = $stdout) { || ... } click to toggle source
# File lib/lessons_indexer/addons/utils.rb, line 2
def with_messages(prior = '', after = '', delimiter = true, output = $stdout)
  return unless block_given?
  prior = String(prior)
  after = String(after)

  output.puts prior.magenta unless prior == ''
  yield
  output.puts after.green unless after == ''
  output.puts "=".yellow * 50 if delimiter
end
within(path, ret = false) { || ... } click to toggle source
# File lib/lessons_indexer/addons/utils.rb, line 21
def within(path, ret = false)
  return unless block_given?
  initial = Dir.getwd
  Dir.chdir(path)
  val = yield
  Dir.chdir(initial) if ret
  return val
rescue Errno::ENOENT
  exit_msg "The provided directory #{path} was not found! Aborting..."
end