Class: Evolution::Repo

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Repo

Returns a new instance of Repo.



5
6
7
8
9
10
# File 'lib/evolution.rb', line 5

def initialize(options = {})
  @path = options[:path] || Dir.pwd
  @results = {}
  @before = options[:before]
  @after = options[:after] || (Date.today << 6).strftime('%Y-%m-%d')
end

Instance Method Details

#reportObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/evolution.rb', line 29

def report
  max_file_length = @results.map{|r| r[0].length}.max

  puts "+---------------+#{'-' * max_file_length}---+"
  puts "| Times Changed | File path #{' ' * (max_file_length - 8) }+"
  puts "+---------------+#{'-' * max_file_length}---+"
  @results.each do |result|
    puts "| #{result[1]}#{" " * (13 - result[1].to_s.length)} | #{result[0]}#{" " * (max_file_length - result[0].to_s.length + 2)}|"
  end
  puts "+---------------+#{'-' * max_file_length}---+"
  nil
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/evolution.rb', line 12

def run
  files = []

  Dir.chdir(@path) do
    files = `git log --after #{@after} --name-only --format='%n'`.split(/\n/).reject{|line| line == ""}
  end

  results = {}

  files.each do |file|
    # TODO This is not optimal
    results[file] = files.count(file)
  end

  @results = results.sort_by{|r| r[1]}.reverse
end