Class: Blammo::Changelog

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Changelog

Returns a new instance of Changelog.



7
8
9
10
# File 'lib/blammo/changelog.rb', line 7

def initialize(path)
  releases_hash  = File.exists?(path) ? YAML.load_file(path) : []
  @releases      = Changelog.parse_releases(releases_hash)
end

Instance Attribute Details

#releasesObject (readonly)

Returns the value of attribute releases.



5
6
7
# File 'lib/blammo/changelog.rb', line 5

def releases
  @releases
end

Class Method Details

.last_sha(releases) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/blammo/changelog.rb', line 35

def self.last_sha(releases)
  commit = nil

  releases.each do |release|
    commit = release.commits.detect {|commit| commit.sha}
    break if commit
  end

  commit ? commit.sha : nil
end

.parse_releases(releases) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/blammo/changelog.rb', line 46

def self.parse_releases(releases)
  releases.map do |release|
    name, commits = release.first

    commits = commits.map do |commit|
      sha, message = commit.is_a?(Hash) ? commit.first : [nil, commit]
      Commit.new(sha, message)
    end.compact

    Release.new(name, commits)
  end
end

Instance Method Details

#add_release(release) ⇒ Object



27
28
29
# File 'lib/blammo/changelog.rb', line 27

def add_release(release)
  @releases.unshift(release) unless release.commits.empty?
end

#refresh(dir, name = nil) ⇒ Object



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

def refresh(dir, name = nil)
  name    ||= Time.now.strftime("%Y%m%d%H%M%S")
  release   = Release.new(name)
  since     = Changelog.last_sha(@releases)

  Git.each_commit(dir, since) do |sha, message|
    if message =~ Commit::COMMIT_RE
      commit = Commit.new(sha, message)
      release.add_commit(commit) if commit.tag
    end
  end

  add_release(release)
end

#to_yaml(options = {}) ⇒ Object



31
32
33
# File 'lib/blammo/changelog.rb', line 31

def to_yaml(options = {})
  @releases.to_yaml(options)
end