module Browser
Private Class Methods
browse(remote)
click to toggle source
Generate and open approprate website from ssh/git link
# File lib/or-browser.rb, line 24 def browse(remote) open prepare remote end
browser()
click to toggle source
Return the right command for opening a website from the terminal
# File lib/or-browser.rb, line 30 def browser case os_name when "mac" "open " when "dos" "start " when "nix" "xdg-open " end end
git_at_to_https(base, url)
click to toggle source
Helper transformations
# File lib/or-browser.rb, line 75 def git_at_to_https(base, url) info = url.partition("@").last host = info.partition(":").first user_repo = info.partition(":").last user_repo.sub!(/\.git$/, "") "#{base}#{host}/#{user_repo}" end
git_colon_to_https(base, url)
click to toggle source
# File lib/or-browser.rb, line 83 def git_colon_to_https(base, url) info = url.partition("://").last info.sub!(/\.git$/, "") base << info end
https_to_app(base, url)
click to toggle source
# File lib/or-browser.rb, line 95 def https_to_app(base, url) app = url.partition(".com/").last app.sub!(/\.git$/, "") base << app end
open(url)
click to toggle source
Make the system call to open up a website
# File lib/or-browser.rb, line 43 def open(url) puts "Opening: ".green + url system browser + url end
prepare(url)
click to toggle source
Parse remote to determine whether it is https/ssh, give link
# File lib/or-browser.rb, line 50 def prepare(url) hb = "https://" # https base url if /^https:\/\/git\.heroku/.match(url) # is heroku, change to app https_to_app hb + "dashboard.heroku.com/apps/", url elsif /^https/.match(url) # is website, return w/o .git ending url.sub(/\.git$/, "") elsif /^git@/.match(url) # git remote w/ @ git_at_to_https hb, url elsif /^git:/.match(url) # git remote w/ : git_colon_to_https hb, url elsif /^ssh/.match(url) # is ssh link, change to website ssh_to_https hb, url else # unknown, return a generic link raise "Malformed remote url: " + url end end
ssh_to_https(base, url)
click to toggle source
# File lib/or-browser.rb, line 89 def ssh_to_https(base, url) info = url.partition("@").last info.sub!(/\.git$/, "") base << info end