Class: CommitHookr

Inherits:
Object
  • Object
show all
Defined in:
lib/commit_hookr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message_file) ⇒ CommitHookr



13
14
15
16
# File 'lib/commit_hookr.rb', line 13

def initialize(message_file)
  self.message_file = message_file
  self.message = ""
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



11
12
13
# File 'lib/commit_hookr.rb', line 11

def message
  @message
end

#message_fileObject

Returns the value of attribute message_file.



11
12
13
# File 'lib/commit_hookr.rb', line 11

def message_file
  @message_file
end

Class Method Details

.call(&block) ⇒ Object



7
8
9
# File 'lib/commit_hookr.rb', line 7

def self.call(&block)
  @@hook = block
end

Instance Method Details

#abort!Object



32
33
34
# File 'lib/commit_hookr.rb', line 32

def abort!
  exit 1
end

#commit!Object



36
37
38
# File 'lib/commit_hookr.rb', line 36

def commit!
  exit 0
end

#original_messageObject



18
19
20
# File 'lib/commit_hookr.rb', line 18

def original_message
  File.read(message_file)
end

#runObject



22
23
24
25
26
# File 'lib/commit_hookr.rb', line 22

def run
  STDIN.reopen '/dev/tty' unless STDIN.tty?
  instance_eval &@@hook
  exit 0
end

#uiObject



28
29
30
# File 'lib/commit_hookr.rb', line 28

def ui
  @highline ||= HighLine.new
end

#write(message) ⇒ Object



40
41
42
43
44
# File 'lib/commit_hookr.rb', line 40

def write(message)
  File.open(message_file, "w+") do |f|
    f.write message
  end
end