class PrivateGemServer::Source::Git
Constants
- DEBOUNCE
Public Instance Methods
refresh!()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 10 def refresh! return if @last_refresh && (Time.now - @last_refresh) < DEBOUNCE prepare_git_files! check_out_or_fetch! find_new_versions! @last_refresh = Time.now end
Private Instance Methods
available_versions()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 84 def available_versions list = '' run! 'git tag -l', cwd: repo_path, output: list, error: logger list.split("\n").select { |tag| tag =~ /^v?\d+(\.\d+)*$/ } end
build_version!(version)
click to toggle source
# File lib/private_gem_server/source/git.rb, line 90 def build_version!(version) target_path = Pathname "#{repo_path}/#{name}-#{version[/\d.*/]}.gem" run! "git checkout tags/#{e version} && gem build #{e name}.gemspec", cwd: repo_path, output: logger, error: logger unless target_path.exist? PrivateGemServer.add target_path if target_path.exist? end
check_out_or_fetch!()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 20 def check_out_or_fetch! if repo_path.join('.git').exist? git 'git fetch', cwd: repo_path else repo_path.mkpath git "git clone #{e url} #{e repo_path}" end end
e(arg)
click to toggle source
# File lib/private_gem_server/source/git.rb, line 96 def e(arg) Shellwords.escape arg end
find_new_versions!()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 78 def find_new_versions! available_versions.each do |version| build_version! version unless PrivateGemServer.has name, version[/\d.*/] end end
git(cmd, **opts)
click to toggle source
# File lib/private_gem_server/source/git.rb, line 45 def git(cmd, **opts) (opts[:env] = (opts[:env] || {}).dup)['GIT_SSH'] = git_ssh_path opts[:output] ||= logger opts[:error] ||= logger run!(cmd, **opts) == 0 end
git_key_path()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 70 def git_key_path @git_key_path ||= temp_path + 'git.key' end
git_ssh_path()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 74 def git_ssh_path @git_ssh_path ||= temp_path + 'git_ssh' end
key()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 29 def key @key ||= @sources.keys[@properties['key']] end
prepare_git_files!()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 57 def prepare_git_files! unless git_key_path.exist? git_key_path.parent.mkpath git_key_path.binwrite key git_key_path.chmod 0400 end unless git_ssh_path.exist? git_ssh_path.parent.mkpath git_ssh_path.write ssh_template % e(git_key_path) git_ssh_path.chmod 0700 end end
repo_path()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 41 def repo_path @repo_path = temp_path + 'repo' end
ssh_template()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 52 def ssh_template "#!/bin/bash\n" << 'ssh -oStrictHostKeyChecking=no -i %s "$@"' end
temp_path()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 37 def temp_path @temp_path ||= @sources.temp_path + 'git' + name end
url()
click to toggle source
# File lib/private_gem_server/source/git.rb, line 33 def url @url ||= @properties['url'] end