module Ruboty::WikiSearch::GitOperation

Public Class Methods

cloned?(uri) click to toggle source
# File lib/ruboty/wiki_search/git_operation.rb, line 53
def cloned?(uri)
  dir = sync_directory(uri)
  Dir.exist?(dir) && Git.open(dir)
rescue ArgumentError
  FileUtils.rm_rf(dir)
  false
end
repo_urls() click to toggle source
# File lib/ruboty/wiki_search/git_operation.rb, line 41
def repo_urls
  ENV['RUBOTY_WIKI_SEARCH_REPOS'].split(',')
end
repos_directory() click to toggle source
# File lib/ruboty/wiki_search/git_operation.rb, line 45
def repos_directory
  ENV['RUBOTY_WIKI_SEARCH_DIRECTORY'] || File.realpath("#{__dir__}/../../../repos")
end
sync!() click to toggle source
# File lib/ruboty/wiki_search/git_operation.rb, line 28
def sync!
  repo_urls.each do |url|
    u = URI.parse(url)
    if cloned?(u)
      git = Git.open(sync_directory(u))
      git.checkout('master')
      git.pull
    else
      Git.clone(url, sync_directory(u))
    end
  end
end
sync_directory(uri) click to toggle source
# File lib/ruboty/wiki_search/git_operation.rb, line 49
def sync_directory(uri)
  "#{repos_directory}/#{uri.host}#{uri.path.gsub(/\.wiki\.git$/, '')}"
end