Class: Hookers::Changelog::Changelogger

Inherits:
Object
  • Object
show all
Defined in:
lib/hookers/changelog/changelogger.rb

Instance Method Summary collapse

Constructor Details

#initialize(project = Project.discover) ⇒ Changelogger

Returns a new instance of Changelogger.



8
9
10
# File 'lib/hookers/changelog/changelogger.rb', line 8

def initialize(project = Project.discover)
  @project = project
end

Instance Method Details

#generate(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hookers/changelog/changelogger.rb', line 12

def generate(options = {})
  from = options[:from] || History.first
  to = options[:to] || "HEAD"
  lines = History.between(from, to)
  parser = Parser.new(@project)
  commits = lines.map { |e| parser.parse(e) }.flatten

  output = StringIO.new

  types = Hash[commits.group_by(&:type).map { |type, commits| [type, commits.group_by(&:identifier)] }]
  types.each_pair do |type, commits|
    output.puts "\n*** #{type}S ***"
    commits.each_pair do |identifier, commits|
      output.puts "\n * #{identifier}: - #{commits.first.uri}"
      commits.each do |affected|
        output.puts "   - #{affected.commit.message} - #{affected.commit.uri}"
      end
    end
  end

  output.rewind
  output.read
end