module Helpers
Public Instance Methods
file()
click to toggle source
# File lib/oliver/helpers.rb, line 4 def file file = File.read('.oliver') return JSON.parse(file) end
install()
click to toggle source
# File lib/oliver/helpers.rb, line 38 def install # install all repos on the list that aren't local log('.oliver does not exist', :error) unless oliver_exists? log('.oliver is empty', :error) if file.empty? file.map do |user, repos| repos.each do |repo| url = 'https://github.com/' endpoint = "#{user}/#{repo}" if File.directory? repo # just be silent because this gets annoying quickly # puts log("#{repo} already exists", :warning) else begin g = Git.clone(url + endpoint, repo, :path => '.') puts log("#{repo} was cloned successfully", :success) if File.directory? repo rescue puts log("#{repo} failed to clone", :warning) end end end end end
local_repos()
click to toggle source
# File lib/oliver/helpers.rb, line 9 def local_repos folders = Dir.entries('.').reject do |folder| folder['.'] || folder['..'] | folder['.oliver'] end return folders.sort end
log(text, priority=:default)
click to toggle source
# File lib/oliver/helpers.rb, line 28 def log(text, priority=:default) arrow = "==>" legend = { :default => :blue, :warning => :yellow, :error => :red, :success => :green } return "#{arrow.colorize(legend[priority])} #{text}" end
oliver_exists?()
click to toggle source
# File lib/oliver/helpers.rb, line 24 def oliver_exists? File.exists?('.oliver') end
remove()
click to toggle source
# File lib/oliver/helpers.rb, line 63 def remove # check local repos and remove them if they're not in tracked_repos local_repos.each do |repo| unless tracked_repos.include? repo # remove repo # check w user first!! be like, yo are you sure about this buddy print log("Delete #{repo}? (y/n): ", :warning) response = STDIN.gets.chomp.downcase if response == 'y' puts log("Deleting #{repo}") FileUtils.rm_rf(repo) else puts log("Keeping #{repo}") end end end end
tracked_repos()
click to toggle source
# File lib/oliver/helpers.rb, line 16 def tracked_repos tracked = [] file.map do |user, repos| tracked.push(repos) end return tracked.sort.flatten end