class EmojiCommit::Cli
Public Instance Methods
check_for_git()
click to toggle source
# File lib/file-tasks.rb, line 68 def check_for_git unless Dir.exist?('.git') puts 'Git has not been initialised in this directory. Bye' exit end end
filenames()
click to toggle source
# File lib/file-tasks.rb, line 79 def filenames ['emoji-script.rb', 'emoji-commit-msg.rb', 'commit-msg', 'emojis.json'] end
install()
click to toggle source
# File lib/file-tasks.rb, line 9 def install check_for_git puts 'You are about to overwrite any existing Git commit hook with the emoji script' puts 'Is that OK? (Y|n)' answer = STDIN.gets.strip.downcase if answer == 'n' puts 'Fine whatever. Bye' exit elsif answer == '' puts 'Great, installing into .git/hooks' elsif answer != 'y' puts 'Pardon? Oh who cares. Bye' exit else puts 'Great, installing into .git/hooks' end if File.exist?('.git/hooks/commit-msg') then FileUtils.rm('.git/hooks/commit-msg') end filenames.each do |filename| FileUtils.cp("#{path}/#{filename}", ".git/hooks/#{filename}") FileUtils.chmod(0755, ".git/hooks/#{filename}") end puts 'Installed scripts successfully. Commit emoji-ful messages!' end
path()
click to toggle source
# File lib/file-tasks.rb, line 75 def path File.dirname(File.expand_path(__FILE__)) end
uninstall()
click to toggle source
# File lib/file-tasks.rb, line 40 def uninstall check_for_git puts 'You are about to uninstall the emoji Git commit hook' puts 'Is that OK? (y|n)' answer = STDIN.gets.strip.downcase if answer == 'n' puts 'Good choice. Bye' exit elsif answer != 'y' puts 'Pardon? Oh who cares. Bye' exit else puts 'As long as you\'re sure :( Removing files now' end filenames.each do |filename| FileUtils.rm(".git/hooks/#{filename}") if File.exists?(".git/hooks/#{filename}") end FileUtils.cp("#{path}/commit-msg.sample", ".git/hooks/commit-msg.sample") unless File.exist?('.git/hooks/commit-msg.sample') puts 'Uninstalled scripts successfully. Enjoy your boring emoji-less life.' end