Class: Nearmiss::Project
- Inherits:
-
Object
- Object
- Nearmiss::Project
- Defined in:
- lib/nearmiss-ruby/project.rb
Overview
Class to parse GitHub repository owner and name from URLs and to generate URLs
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
Class Method Summary collapse
-
.from_url(url) ⇒ Repository
Instantiate from a GitHub repository URL.
-
.path(project) ⇒ String
Get the api path for a repo.
Instance Method Summary collapse
-
#id_api_path ⇒ String
Api path for id identified repos.
-
#initialize(project) ⇒ Project
constructor
A new instance of Project.
-
#path ⇒ String
Project API path.
-
#slug ⇒ String
(also: #to_s)
Project owner/name.
-
#url ⇒ String
Project URL based on Client#web_endpoint.
Constructor Details
#initialize(project) ⇒ Project
Returns a new instance of Project.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nearmiss-ruby/project.rb', line 16 def initialize(project) case project # when Integer # @id = project when String @id = project # @owner, @name = repo.split('/') # unless @owner && @name # raise ArgumentError, "Invalid Repository. Use user/repo format." # end when Project @id = project.id # @name = repo.name when Hash @id = project[:project] ||= project[:id] # @owner = repo[:owner] ||= repo[:user] ||= repo[:username] end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/nearmiss-ruby/project.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/nearmiss-ruby/project.rb', line 6 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
6 7 8 |
# File 'lib/nearmiss-ruby/project.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/nearmiss-ruby/project.rb', line 11 def self.from_url(url) Project.new(URI.parse(url).path[1..-1]) end |
.path(project) ⇒ String
Get the api path for a repo
51 52 53 |
# File 'lib/nearmiss-ruby/project.rb', line 51 def self.path(project) new(project).path end |
Instance Method Details
#id_api_path ⇒ String
Returns Api path for id identified repos.
61 62 63 |
# File 'lib/nearmiss-ruby/project.rb', line 61 def id_api_path "projects/#{@id}" end |
#path ⇒ String
Returns Project API path.
43 44 45 46 |
# File 'lib/nearmiss-ruby/project.rb', line 43 def path # return named_api_path if @owner && @name return id_api_path if @id end |
#slug ⇒ String Also known as: to_s
Project owner/name
37 38 39 |
# File 'lib/nearmiss-ruby/project.rb', line 37 def slug # "#{@owner}/#{@name}" end |
#url ⇒ String
Project URL based on Client#web_endpoint
67 68 69 |
# File 'lib/nearmiss-ruby/project.rb', line 67 def url # "#{Octokit.web_endpoint}#{slug}" end |