Sha256: a99144683233cebda4ff58a50b06c6b4e7564b337cd92ccbf9c250994e3e7f30

Contents?: true

Size: 735 Bytes

Versions: 22

Compression:

Stored size: 735 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

22 entries across 22 versions & 1 rubygems

Version Path
octokit-1.25.0 lib/octokit/repository.rb
octokit-1.24.0 lib/octokit/repository.rb
octokit-1.23.0 lib/octokit/repository.rb
octokit-1.22.0 lib/octokit/repository.rb
octokit-1.21.0 lib/octokit/repository.rb
octokit-1.20.0 lib/octokit/repository.rb
octokit-1.19.0 lib/octokit/repository.rb
octokit-1.18.0 lib/octokit/repository.rb
octokit-1.17.1 lib/octokit/repository.rb
octokit-1.17.0 lib/octokit/repository.rb
octokit-1.15.1 lib/octokit/repository.rb
octokit-1.15.0 lib/octokit/repository.rb
octokit-1.14.0 lib/octokit/repository.rb
octokit-1.13.0 lib/octokit/repository.rb
octokit-1.12.0 lib/octokit/repository.rb
octokit-1.11.0 lib/octokit/repository.rb
octokit-1.10.0 lib/octokit/repository.rb
octokit-1.9.4 lib/octokit/repository.rb
octokit-1.9.3 lib/octokit/repository.rb
octokit-1.9.2 lib/octokit/repository.rb