Class: EmojiCommit::Msg
- Inherits:
-
Object
- Object
- EmojiCommit::Msg
- Defined in:
- lib/emoji-commit-msg.rb
Instance Attribute Summary collapse
-
#msg_file ⇒ Object
Returns the value of attribute msg_file.
Instance Method Summary collapse
- #edit_commit_msg ⇒ Object
- #emoji_exists?(message) ⇒ Boolean
- #get_emoji ⇒ Object
-
#initialize(file) ⇒ Msg
constructor
A new instance of Msg.
- #path_to_emojis ⇒ Object
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_file ⇒ Object
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_msg ⇒ Object
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
11 12 13 |
# File 'lib/emoji-commit-msg.rb', line 11 def emoji_exists?() .match(/^:(-|\+|non-|e-\w+)?(\w+):/) ? true : false end |
#get_emoji ⇒ Object
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_emojis ⇒ Object
23 24 25 |
# File 'lib/emoji-commit-msg.rb', line 23 def path_to_emojis "#{Dir.pwd}/.git/hooks/emojis.json" end |