Sha256: eea5765796750e13dbc304fdf7c67477a3e0755f7e2ccb077497f59dcc6b9624

Contents?: true

Size: 744 Bytes

Versions: 14

Compression:

Stored size: 744 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].compact.join('/')
    end

    def to_s
      self.slug
    end

    def url
      "https://github.com/#{slug}"
    end

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

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
octokit-0.6.4 lib/octokit/repository.rb
octokit-0.6.3 lib/octokit/repository.rb
octokit-0.6.2 lib/octokit/repository.rb
hybridgroup-octokit-0.6.3 lib/octokit/repository.rb
hybridgroup-octokit-0.6.2 lib/octokit/repository.rb
hybridgroup-octokit-0.6.1 lib/octokit/repository.rb
xn-octokit-0.6.1 lib/octokit/repository.rb
octokit-0.6.1 lib/octokit/repository.rb
octokit-0.6.0 lib/octokit/repository.rb
octokit-0.5.2 lib/octokit/repository.rb
octokit-0.5.1 lib/octokit/repository.rb
octokit-0.5.0 lib/octokit/repository.rb
octokit-0.4.1 lib/octokit/repository.rb
octokit-0.4.0 lib/octokit/repository.rb