Class: Hub::Context::Remote

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



387
388
389
# File 'lib/hub/context.rb', line 387

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

#projectObject



391
392
393
394
395
396
397
398
# File 'lib/hub/context.rb', line 391

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

#uri_parse(uri) ⇒ Object



418
419
420
421
422
423
424
425
# File 'lib/hub/context.rb', line 418

def uri_parse uri
  uri = URI.parse uri
  if uri.host != local_repo.default_host
    ssh = local_repo.ssh_config
    uri.host = ssh.get_value(uri.host, :HostName) { uri.host }
  end
  uri
end

#urlsObject



400
401
402
403
404
405
406
407
408
409
# File 'lib/hub/context.rb', line 400

def urls
  @urls ||= raw_urls.map do |url|
    with_normalized_url(url) do |normalized|
      begin
        uri_parse(normalized)
      rescue URI::InvalidURIError
      end
    end
  end
end

#with_normalized_url(url) ⇒ Object



411
412
413
414
415
416
# File 'lib/hub/context.rb', line 411

def with_normalized_url(url)
  if url =~ %r{^[\w-]+://} || url =~ %r{^([^/]+?):}
    url = "ssh://#{$1}/#{$'}" if $1
    yield url
  end
end