Class: Hub::Context::Remote

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



330
331
332
# File 'lib/hub/context.rb', line 330

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

#projectObject



334
335
336
337
338
339
340
341
# File 'lib/hub/context.rb', line 334

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

#uri_parse(uri) ⇒ Object



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

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



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/hub/context.rb', line 343

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