class EmojiCommit::Msg
Attributes
msg_file[RW]
Public Class Methods
new(file)
click to toggle source
# File lib/emoji-commit-msg.rb, line 7 def initialize(file) @msg_file = file end
Public Instance Methods
edit_commit_msg()
click to toggle source
# File lib/emoji-commit-msg.rb, line 27 def edit_commit_msg commit_msg = File.read(@msg_file) return if emoji_exists?(commit_msg) File.write(@msg_file, "#{get_emoji} #{commit_msg}") end
emoji_exists?(message)
click to toggle source
# File lib/emoji-commit-msg.rb, line 11 def emoji_exists?(message) message.match(/^:(-|\+|non-|e-\w+)?(\w+):/) ? true : false end
get_emoji()
click to toggle source
# File lib/emoji-commit-msg.rb, line 15 def get_emoji puts Dir.pwd emojis_file = File.read(path_to_emojis) emojis_hash = JSON.parse(emojis_file) emojis_hash[emojis_hash.keys.sample].strip end
path_to_emojis()
click to toggle source
# File lib/emoji-commit-msg.rb, line 23 def path_to_emojis "#{Dir.pwd}/.git/hooks/emojis.json" end