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
Instance Attribute Summary collapse
-
#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.
Instance Method Summary collapse
-
#initialize(repo) ⇒ Repository
constructor
A new instance of Repository.
-
#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.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/octokit/repository.rb', line 15 def initialize(repo) case repo when String @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] end end |
Instance Attribute Details
#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
11 12 13 |
# File 'lib/octokit/repository.rb', line 11 def self.from_url(url) Repository.new(URI.parse(url).path[1..-1]) end |
Instance Method Details
#slug ⇒ String Also known as: to_s
Repository owner/name
30 31 32 |
# File 'lib/octokit/repository.rb', line 30 def slug "#{@owner}/#{@name}" end |
#url ⇒ String
Repository URL based on Client#web_endpoint
37 38 39 |
# File 'lib/octokit/repository.rb', line 37 def url "#{Octokit.web_endpoint}#{slug}" end |