Class: EmojiCommit::Msg

Inherits:
Object
  • Object
show all
Defined in:
lib/emoji-commit-msg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Msg

Returns a new instance of Msg.



7
8
9
# File 'lib/emoji-commit-msg.rb', line 7

def initialize(file)
  @msg_file = file
end

Instance Attribute Details

#msg_fileObject

Returns the value of attribute msg_file.



5
6
7
# File 'lib/emoji-commit-msg.rb', line 5

def msg_file
  @msg_file
end

Instance Method Details

#edit_commit_msgObject



27
28
29
30
31
# 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) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/emoji-commit-msg.rb', line 11

def emoji_exists?(message)
  message.match(/^:(-|\+|non-|e-\w+)?(\w+):/) ? true : false
end

#get_emojiObject



15
16
17
18
19
20
21
# 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_emojisObject



23
24
25
# File 'lib/emoji-commit-msg.rb', line 23

def path_to_emojis
  "#{Dir.pwd}/.git/hooks/emojis.json"
end