Module: Helpers
- Defined in:
- lib/oliver/helpers.rb
Class Method Summary collapse
- .file ⇒ Object
- .install ⇒ Object
- .local_repos ⇒ Object
- .log(text, priority = :default) ⇒ Object
- .oliver_exists? ⇒ Boolean
- .remove ⇒ Object
- .tracked_repos ⇒ Object
Class Method Details
.file ⇒ Object
4 5 6 7 |
# File 'lib/oliver/helpers.rb', line 4 def file file = File.read('.oliver') return JSON.parse(file) end |
.install ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 ⇒ Object
9 10 11 12 13 14 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# 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? ⇒ Boolean
24 25 26 |
# File 'lib/oliver/helpers.rb', line 24 def oliver_exists? File.exists?('.oliver') end |
.remove ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
16 17 18 19 20 21 22 |
# 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 |