Class: Octokit::Repository
- Inherits:
-
Object
- Object
- Octokit::Repository
- Defined in:
- lib/octokit/repository.rb
Overview
Class to parse GitHub repository owner and name from URLs and to generate URLs
Constant Summary collapse
- NAME_WITH_OWNER_PATTERN =
/\A[\w.-]+\/[\w.-]+\z/i
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
(also: #repo)
Returns the value of attribute name.
-
#owner ⇒ Object
(also: #user, #username)
Returns the value of attribute owner.
Class Method Summary collapse
-
.from_url(url) ⇒ Repository
Instantiate from a GitHub repository URL.
-
.path(repo) ⇒ String
Get the api path for a repo.
Instance Method Summary collapse
-
#id_api_path ⇒ String
Api path for id identified repos.
-
#initialize(repo) ⇒ Repository
constructor
A new instance of Repository.
-
#named_api_path ⇒ String
Api path for owner/name identified repos.
-
#path ⇒ String
Repository API path.
-
#slug ⇒ String
(also: #to_s)
Repository owner/name.
-
#url ⇒ String
Repository URL based on Client#web_endpoint.
Constructor Details
#initialize(repo) ⇒ Repository
Returns a new instance of Repository.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/octokit/repository.rb', line 18 def initialize(repo) case repo when Integer @id = repo when NAME_WITH_OWNER_PATTERN @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] else raise_invalid_repository! end if @owner && @name validate_owner_and_name! end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/octokit/repository.rb', line 6 def id @id end |
#name ⇒ Object Also known as: repo
Returns the value of attribute name.
6 7 8 |
# File 'lib/octokit/repository.rb', line 6 def name @name end |
#owner ⇒ Object 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
12 13 14 |
# File 'lib/octokit/repository.rb', line 12 def self.from_url(url) Repository.new(URI.parse(url).path[1..-1]) end |
.path(repo) ⇒ String
Get the api path for a repo
54 55 56 |
# File 'lib/octokit/repository.rb', line 54 def self.path repo new(repo).path end |
Instance Method Details
#id_api_path ⇒ String
Returns Api path for id identified repos.
64 65 66 |
# File 'lib/octokit/repository.rb', line 64 def id_api_path "repositories/#{@id}" end |
#named_api_path ⇒ String
Returns Api path for owner/name identified repos.
59 60 61 |
# File 'lib/octokit/repository.rb', line 59 def named_api_path "repos/#{slug}" end |
#path ⇒ String
Returns Repository API path.
46 47 48 49 |
# File 'lib/octokit/repository.rb', line 46 def path return named_api_path if @owner && @name return id_api_path if @id end |
#slug ⇒ String Also known as: to_s
Repository owner/name
40 41 42 |
# File 'lib/octokit/repository.rb', line 40 def slug "#{@owner}/#{@name}" end |
#url ⇒ String
Repository URL based on Client#web_endpoint
70 71 72 |
# File 'lib/octokit/repository.rb', line 70 def url "#{Octokit.web_endpoint}#{slug}" end |