Sha256: 31f0b0fe83cdd4272c749bd9716659ee172fc2d59ee6a113c23b1a5e1318076c

Contents?: true

Size: 736 Bytes

Versions: 4

Compression:

Stored size: 736 Bytes

Contents

require 'addressable/uri'

module Octokit
  class Repository
    attr_accessor :username, :name

    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

    def slug
      "#{@username}/#{@name}"
    end

    def to_s
      self.slug
    end

    def url
      "#{Octokit.web_endpoint}/#{slug}"
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
octokit-1.8.0 lib/octokit/repository.rb
octokit-1.7.0 lib/octokit/repository.rb
octokit-1.6.1 lib/octokit/repository.rb
octokit-1.6.0 lib/octokit/repository.rb