Class: Todidnt::CLI

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

Constant Summary collapse

VALID_COMMANDS =
%w{generate clear}

Class Method Summary collapse

Class Method Details

.clear(options) ⇒ Object



50
51
52
53
54
# File 'lib/todidnt.rb', line 50

def self.clear(options)
  puts "Deleting cache..."
  Cache.clear!
  puts "Done!"
end

.generate(options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/todidnt.rb', line 26

def self.generate(options)
  GitRepo.new(options[:path]).run do |path|
    history = GitHistory.new
    buckets, authors = history.timeline!

    lines = TodoLine.all(["TODO"])
    lines.each do |todo|
      blames = history.blames[todo.raw_content]

      if blames && ( = blames.pop)
        todo.author = [:name]
        todo.timestamp = [:time]
      else
        todo.author = "(Not yet committed)"
        todo.timestamp = Time.now.to_i
      end
    end

    file_path = HTMLGenerator.generate(:all, :all_lines => lines.sort_by(&:timestamp).reverse)
    file_path = HTMLGenerator.generate(:history, :data => {:history => buckets.map {|h| h[:authors].merge('Date' => h[:timestamp]) }, :authors => authors.to_a})
    Launchy.open("file://#{file_path}")
  end
end

.run(command, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/todidnt.rb', line 15

def self.run(command, options)
  command ||= 'generate'

  if command && VALID_COMMANDS.include?(command)
    self.send(command, options)
  elsif command
    $stderr.puts("Sorry, `#{command}` is not a valid command.")
    exit
  end
end