Class: Historian::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/historian/cli.rb

Overview

require ‘thor/actions’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/historian/cli.rb', line 10

def initialize(*)
  super
  @repo_directory = ProjectScout.scan Dir.pwd, :for => [ :git_repository ]

  history_file = File.join(repo_directory, "History.txt")
  unless File.exists? history_file
    File.open history_file, "w"
  end
  @history = File.open history_file, File::RDWR
  history.sync = true
  history.extend Historian::HistoryFile
  self.git = Historian::Git.new(repo_directory, history)
end

Instance Attribute Details

#gitObject

Returns the value of attribute git.



6
7
8
# File 'lib/historian/cli.rb', line 6

def git
  @git
end

#historyObject

Returns the value of attribute history.



6
7
8
# File 'lib/historian/cli.rb', line 6

def history
  @history
end

#repo_directoryObject

Returns the value of attribute repo_directory.



6
7
8
# File 'lib/historian/cli.rb', line 6

def repo_directory
  @repo_directory
end

Instance Method Details

#commit_msg(message_file) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/historian/cli.rb', line 25

def commit_msg(message_file)
  return nil if File.exists? amend_flag_file

  history_updated = false
  release = nil
  new_message = []
  File.open(message_file).each_line do |line|
    line = Historian::CommitMessage.parse_line line
    new_message << line.to_s unless line.suppressed?
    case line.significance
    when :minor, :major, :patch
      history.update_history line.significance => line.to_message_s
      history_updated = true
    when :release
      release = line.to_message_s
    end
  end

  if release
    history_updated = true
    history.update_history :release => release
    File.open release_flag_file, "w"
  end

  if history_updated
    File.open amend_flag_file, "w"
    File.open(message_file,"w") { |f| f.puts new_message }
  end
end

#installObject



56
57
58
59
# File 'lib/historian/cli.rb', line 56

def install
  git.install_hook :commit_msg
  git.install_hook :post_commit
end

#post_commitObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/historian/cli.rb', line 62

def post_commit
  if File.exists? amend_flag_file
    File.unlink amend_flag_file
    git.bundle_history_file
  end

  if File.exists? release_flag_file
    File.unlink release_flag_file
    git.tag_release
  end
end