class TiyoHw::Setup
Attributes
url[RW]
Public Class Methods
new(url)
click to toggle source
# File lib/tiyo_hw/setup.rb, line 6 def initialize(url) @url = url end
Public Instance Methods
clean_dir()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 28 def clean_dir FileUtils.rm_rf(File.join(homework_path, dir_name)) end
cmd()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 40 def cmd setup clean_dir cmds = [] cmds << "cd #{homework_path}" cmds << "git clone #{git_url} #{dir_name}" cmds << "cd #{dir_name}" cmds << "git checkout #{sha} -b submitted_assignment" if sha cmds << "#{EDITOR} ." cmds.join(" && ") end
dir_name()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 24 def dir_name git_url.split(%r{[\/\.]})[-3..-2].join("-") end
gist?()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 20 def gist? /gist\.github\.com/.match(url) end
git_url()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 15 def git_url final_url = url.split("/tree/").first "#{final_url}#{'.git' unless final_url.end_with?('.git')}" end
homework_path()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 32 def homework_path File.expand_path(HOMEWORK_DIR) end
setup()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 36 def setup FileUtils.mkdir_p homework_path end
sha()
click to toggle source
# File lib/tiyo_hw/setup.rb, line 10 def sha matches = /\b[0-9a-f]{5,40}\b/.match(url) matches.to_s if matches && !gist? end