Class: Octokit::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/octokit/repository.rb

Overview

Class to parse GitHub repository owner and name from URLs and to generate URLs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Repository



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/octokit/repository.rb', line 15

def initialize(repo)
  case repo
  when Integer
    @id = repo
  when String
    @owner, @name = repo.split('/')
    unless @owner && @name
      raise ArgumentError, "Invalid Repository. Use user/repo format."
    end
  when Repository
    @owner = repo.owner
    @name = repo.name
  when Hash
    @name = repo[:repo] ||= repo[:name]
    @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id



6
7
8
# File 'lib/octokit/repository.rb', line 6

def id
  @id
end

#nameObject Also known as: repo

Returns the value of attribute name



6
7
8
# File 'lib/octokit/repository.rb', line 6

def name
  @name
end

#ownerObject Also known as: user, username

Returns the value of attribute owner



6
7
8
# File 'lib/octokit/repository.rb', line 6

def owner
  @owner
end

Class Method Details

.from_url(url) ⇒ Repository

Instantiate from a GitHub repository URL



11
12
13
# File 'lib/octokit/repository.rb', line 11

def self.from_url(url)
  Repository.new(URI.parse(url).path[1..-1])
end

.path(repo) ⇒ String

Get the api path for a repo



49
50
51
# File 'lib/octokit/repository.rb', line 49

def self.path repo
  new(repo).path
end

Instance Method Details

#id_api_pathString



59
60
61
# File 'lib/octokit/repository.rb', line 59

def id_api_path
  "repositories/#{@id}"
end

#named_api_pathString



54
55
56
# File 'lib/octokit/repository.rb', line 54

def named_api_path
  "repos/#{slug}"
end

#pathString



41
42
43
44
# File 'lib/octokit/repository.rb', line 41

def path
  return named_api_path if @owner && @name
  return id_api_path if @id
end

#slugString Also known as: to_s

Repository owner/name



35
36
37
# File 'lib/octokit/repository.rb', line 35

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

#urlString

Repository URL based on Client#web_endpoint



65
66
67
# File 'lib/octokit/repository.rb', line 65

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