lib/github_url.rb in github_url-0.1.0 vs lib/github_url.rb in github_url-0.2.0
- old
+ new
@@ -1,16 +1,17 @@
class GithubUrl
- attr_accessor :url, :default_branch
+ attr_accessor :url
- GITHUB_HOST = "github.com"
+ GITHUB_HOST = "github.com".freeze
class Invalid < StandardError
end
- def initialize(url, default_branch = "master")
+ def initialize(url:, default_branch: "master", host: GITHUB_HOST)
@default_branch = default_branch
@url = url
+ @host = host
validate_url
end
def organization
@@ -34,17 +35,17 @@
def default_branch?
(["blob", "tree", "raw"] & url_path).empty?
end
def validate_url
- raise(Invalid, "Must contain #{GITHUB_HOST}") unless url.split("/").any? { |e| e.include?(GITHUB_HOST) }
+ 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
def url_path
url_arr = url.split("/")
- github_index = url_arr.index { |e| e.include?(GITHUB_HOST) }
- url_arr[github_index + 1..-1]
+ host_index = url_arr.index { |e| e.include?(@host) }
+ url_arr[host_index + 1..-1]
end
end