Sha256: f12f2960e5c1874fddd6919f6714b96a967220cbcc7c13cd793d092937235a07

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require 'addressable/uri'

module Octokit
  
  # Class to parse GitHub repository owner and name from 
  # URLs and to generate URLs
  class Repository
    attr_accessor :username, :name

    # Instantiate from a GitHub repository URL
    #
    # @return [Repository]
    def self.from_url(url)
      Repository.new(Addressable::URI.parse(url).path[1..-1])
    end

    def initialize(repo)
      case repo
      when String
        @username, @name = repo.split('/')
      when Repository
        @username = repo.username
        @name = repo.name
      when Hash
        @name = repo[:repo] ||= repo[:name]
        @username = repo[:username] ||= repo[:user] ||= repo[:owner]
      end
    end

    # Repository owner/name
    # @return [String]
    def slug
      "#{@username}/#{@name}"
    end
    alias :to_s :slug

    # Repository URL based on {Octokit::Client#web_endpoint}
    # @return [String]
    def url
      "#{Octokit.web_endpoint}#{slug}"
    end

    alias :user :username
    alias :repo :name
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
octokit-2.0.0.pre lib/octokit/repository.rb