class GithubUrl
Constants
- GITHUB_HOST
- VERSION
Attributes
url[RW]
Public Class Methods
new(url:, default_branch: "master", host: GITHUB_HOST)
click to toggle source
# File lib/github_url.rb, line 9 def initialize(url:, default_branch: "master", host: GITHUB_HOST) @default_branch = default_branch @url = url @host = host validate_url end
Public Instance Methods
branch()
click to toggle source
# File lib/github_url.rb, line 25 def branch default_branch? ? @default_branch : url_path[3] end
organization()
click to toggle source
# File lib/github_url.rb, line 17 def organization url_path[0] end
path()
click to toggle source
# File lib/github_url.rb, line 29 def path default_branch? ? File.join(url_path[2..-1]) : File.join(url_path[4..-1].to_a) end
repository()
click to toggle source
# File lib/github_url.rb, line 21 def repository url_path[1] end
Private Instance Methods
default_branch?()
click to toggle source
# File lib/github_url.rb, line 35 def default_branch? (["blob", "tree", "raw"] & url_path).empty? end
url_path()
click to toggle source
# File lib/github_url.rb, line 47 def url_path url_arr = url.split("/") host_index = url_arr.index { |e| e.include?(@host) } url_arr[host_index + 1..-1] end
validate_url()
click to toggle source
# File lib/github_url.rb, line 39 def validate_url raise(Invalid, "Url cannot be blank.") if url.strip.empty? raise(Invalid, "Must contain #{@host}") unless url.split("/").any? { |e| e.include?(@host) } raise(Invalid, "Missing organization") if organization.nil? raise(Invalid, "Missing repository") if repository.nil? raise(Invalid, "Missing branch") if !default_branch? && url_path[3].nil? end