Class: Hub::Context::Remote

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



393
394
395
# File 'lib/hub/context.rb', line 393

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

#github_urlObject



406
407
408
# File 'lib/hub/context.rb', line 406

def github_url
  urls.detect {|url| local_repo.known_host?(url.host) }
end

#projectObject



397
398
399
400
401
402
403
404
# File 'lib/hub/context.rb', line 397

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

#uri_parse(uri) ⇒ Object



428
429
430
431
432
433
434
435
# File 'lib/hub/context.rb', line 428

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



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

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

#with_normalized_url(url) ⇒ Object



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

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