Class: Grog::GitLog

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

Constant Summary collapse

@@placeholders =
%w{H P an ai s}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ GitLog

Returns a new instance of GitLog.



8
9
10
11
# File 'lib/grog/git_log.rb', line 8

def initialize(options)
  @options = options
  fetch_log
end

Class Method Details

.generate(options) ⇒ Object



19
20
21
# File 'lib/grog/git_log.rb', line 19

def self.generate(options)
  self.new(options).to_s
end

.generate_parsing_argumentsObject



13
14
15
16
17
# File 'lib/grog/git_log.rb', line 13

def self.generate_parsing_arguments
  options = Grog::Options.parse(ARGV)
  generate(:number_of_commits_to_show => options.number_of_commits_to_show,
           :show_datetimes => options.show_datetimes)
end

Instance Method Details

#to_sObject



23
24
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
54
55
56
# File 'lib/grog/git_log.rb', line 23

def to_s
  @log_lines.map do |line|
    values = Hash[*@@placeholders.zip(line.split('|||')).flatten]

    sha = GitLog.short_sha1(values['H'])
    date = GitLog.nice_date_format(values['ai'])
    subject = values['s']
    author = values['an']
    branches = branches(values['H'])
    tags = tags(values['H'])

    line =
      Term::ANSIColor.yellow + sha + ' '

    if @options[:show_datetimes]
      line +=
        Term::ANSIColor.green + date + ' '
    end

    line +=
      Term::ANSIColor.reset + subject + ' ' +
      Term::ANSIColor.green + "(#{author})" + Term::ANSIColor.reset

    unless branches.empty?
      line += " B(" + Term::ANSIColor.red + branches.join(' ') + Term::ANSIColor.reset + ")"
    end

    unless tags.empty?
      line += " T(" + Term::ANSIColor.cyan + tags.join(' ') + Term::ANSIColor.reset + ")"
    end

    line + "\n"
  end.join
end