Class: Octokit::Repository
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/octokit/repository.rb |
Overview
Class to parse GitHub repository owner and name from URLs and to generate URLs
Constant Summary
-
NAME_WITH_OWNER_PATTERN =
# File 'lib/octokit/repository.rb', line 8%r{\A[\w.-]+/[\w.-]+\z}i.freeze
Class Method Summary
-
.from_url(url) ⇒ Repository
Instantiate from a GitHub repository URL.
- .new(repo) ⇒ Repository constructor
-
.path(repo) ⇒ String
Get the api path for a repo.
Instance Attribute Summary
Instance Method Summary
- #id_api_path ⇒ String
- #named_api_path ⇒ String
- #path ⇒ String
-
#slug ⇒ String
(also: #to_s)
Repository
owner/name. -
#to_s
Alias for #slug.
-
#url ⇒ String
Repository
URL based onOctokit::Client#web_endpoint
- #raise_invalid_repository!(repo) private
- #validate_owner_and_name!(repo) private
Constructor Details
.new(repo) ⇒ Repository
# File 'lib/octokit/repository.rb', line 22
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!(repo) end validate_owner_and_name!(repo) if @owner && @name end
Class Method Details
.from_url(url) ⇒ Repository
Instantiate from a GitHub repository URL
.path(repo) ⇒ String
Get the api path for a repo
Instance Attribute Details
#id (rw)
[ GitHub ]#name (rw) Also known as: #repo
[ GitHub ]#owner (rw) Also known as: #user, #username
[ GitHub ]#repo (readonly)
Alias for #name.
# File 'lib/octokit/repository.rb', line 78
alias repo name
#user (readonly)
Alias for #owner.
# File 'lib/octokit/repository.rb', line 76
alias user owner
#username (readonly)
Alias for #owner.
# File 'lib/octokit/repository.rb', line 77
alias username owner
Instance Method Details
#id_api_path ⇒ String
# File 'lib/octokit/repository.rb', line 66
def id_api_path "repositories/#{@id}" end
#named_api_path ⇒ String
# File 'lib/octokit/repository.rb', line 61
def named_api_path "repos/#{slug}" end
#path ⇒ String
# File 'lib/octokit/repository.rb', line 48
def path return named_api_path if @owner && @name return id_api_path if @id end
#raise_invalid_repository!(repo) (private)
# File 'lib/octokit/repository.rb', line 88
def raise_invalid_repository!(repo) msg = "#{repo.inspect} is invalid as a repository identifier. " \ 'Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' raise Octokit::InvalidRepository, msg end
#slug ⇒ String
Also known as: #to_s
Repository
owner/name
# File 'lib/octokit/repository.rb', line 42
def slug "#{@owner}/#{@name}" end
#to_s
Alias for #slug.
# File 'lib/octokit/repository.rb', line 45
alias to_s slug
#url ⇒ String
Repository
URL based on Octokit::Client#web_endpoint
# File 'lib/octokit/repository.rb', line 72
def url "#{Octokit.web_endpoint}#{slug}" end
#validate_owner_and_name!(repo) (private)
[ GitHub ]# File 'lib/octokit/repository.rb', line 82
def validate_owner_and_name!(repo) if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI) raise_invalid_repository!(repo) end end