Sha256: 4ff28ddac336b8efee557dca25f718a0e0f41ba510986300ffb77988247aac78

Contents?: true

Size: 988 Bytes

Versions: 25

Compression:

Stored size: 988 Bytes

Contents

module Octokit

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

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

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

    # Repository owner/name
    # @return [String]
    def slug
      "#{@owner}/#{@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 :owner
    alias :username :owner
    alias :repo :name
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
octokit-3.1.2 lib/octokit/repository.rb
octokit-3.1.0 lib/octokit/repository.rb
octokit-3.0.0 lib/octokit/repository.rb
octokit-3.0.0.pre lib/octokit/repository.rb
octokit-2.7.2 lib/octokit/repository.rb
octokit-2.7.1 lib/octokit/repository.rb
octokit-2.7.0 lib/octokit/repository.rb
octokit-2.6.3 lib/octokit/repository.rb
octokit-2.6.2 lib/octokit/repository.rb
octokit-2.6.1 lib/octokit/repository.rb
octokit-2.6.0 lib/octokit/repository.rb
octokit-2.5.1 lib/octokit/repository.rb
octokit-2.5.0 lib/octokit/repository.rb
octokit-2.4.0 lib/octokit/repository.rb
octokit-2.3.1 lib/octokit/repository.rb
octokit-2.3.0 lib/octokit/repository.rb
octokit-2.2.0 lib/octokit/repository.rb
octokit-2.1.2 lib/octokit/repository.rb
octokit-2.1.1 lib/octokit/repository.rb
octokit-2.1.0 lib/octokit/repository.rb