Class: Hub::Context::Remote

Inherits:
Struct
  • Object
show all
Defined in:
lib/hub/context.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



357
358
359
# File 'lib/hub/context.rb', line 357

def ==(other)
  other.respond_to?(:to_str) ? name == other.to_str : super
end

#projectObject



361
362
363
364
365
366
367
368
# File 'lib/hub/context.rb', line 361

def project
  urls.each_value { |url|
    if valid = GithubProject.from_url(url, local_repo)
      return valid
    end
  }
  nil
end

#uri_parse(uri) ⇒ Object



388
389
390
391
392
393
# File 'lib/hub/context.rb', line 388

def uri_parse uri
  uri = URI.parse uri
  uri.host = local_repo.ssh_config.get_value(uri.host, 'hostname') { uri.host }
  uri.user = local_repo.ssh_config.get_value(uri.host, 'user') { uri.user }
  uri
end

#urlsObject



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/hub/context.rb', line 370

def urls
  return @urls if defined? @urls
  @urls = {}
  local_repo.git_command('remote -v').to_s.split("\n").map do |line|
    next if line !~ /^(.+?)\t(.+) \((.+)\)$/
    remote, uri, type = $1, $2, $3
    next if remote != self.name
    if uri =~ %r{^[\w-]+://} or uri =~ %r{^([^/]+?):}
      uri = "ssh://#{$1}/#{$'}" if $1
      begin
        @urls[type] = uri_parse(uri)
      rescue URI::InvalidURIError
      end
    end
  end
  @urls
end