class Jive::Repo

Constants

SSH_REGEX

Public Class Methods

current() click to toggle source
# File lib/jive/repo.rb, line 32
def current
  @current ||= new(Pathname.pwd)
end
new(path) click to toggle source
# File lib/jive/repo.rb, line 7
def initialize(path)
  @repo = Rugged::Repository.new(path.to_s)
end

Public Instance Methods

branch() click to toggle source
# File lib/jive/repo.rb, line 27
def branch
  uri.path[1..-1]
end
canonical_url() click to toggle source
# File lib/jive/repo.rb, line 15
def canonical_url
  remote = @repo.remotes.find { |x| x.name == "origin" }
  return if remote.nil?

  ssh?(remote) ? url_for_ssh(remote) : url_for(remote)
end
nwo() click to toggle source
# File lib/jive/repo.rb, line 22
def nwo
  segments = uri.path.split("/")
  "#{segments[1]}/#{segments[2].gsub(".git", "")}"
end
uri() click to toggle source
# File lib/jive/repo.rb, line 11
def uri
  @uri ||= URI.parse(canonical_url)
end

Private Instance Methods

ssh?(remote) click to toggle source
# File lib/jive/repo.rb, line 39
def ssh?(remote)
  remote.url.match?(SSH_REGEX)
end
url_for(remote) click to toggle source
# File lib/jive/repo.rb, line 54
def url_for(remote)
  uri = URI.parse(remote.url)
  [uri.host, uri.path, @repo.head.name].join("/")
end
url_for_ssh(remote) click to toggle source
# File lib/jive/repo.rb, line 43
def url_for_ssh(remote)
  match = remote.url.match(SSH_REGEX)
  [
    "https:/",
    match[:host],
    match[:account],
    match[:repo],
    @repo.head.name
  ].join("/")
end