changelog 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +1 -1
- data/changelog.gemspec +1 -1
- data/lib/changelog.rb +30 -15
- data/spec/changelog_spec.rb +4 -4
- metadata +4 -4
data/CHANGELOG
CHANGED
data/LICENSE
CHANGED
data/changelog.gemspec
CHANGED
@@ -8,7 +8,7 @@ require "base64"
|
|
8
8
|
|
9
9
|
Gem::Specification.new do |s|
|
10
10
|
s.name = "changelog"
|
11
|
-
s.version = "0.
|
11
|
+
s.version = "0.5"
|
12
12
|
s.authors = ["Jakub Šťastný aka Botanicus"]
|
13
13
|
s.homepage = "http://github.com/botanicus/changelog"
|
14
14
|
s.summary = "Simple CHANGELOG parser for Ruby 1.9"
|
data/lib/changelog.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class CHANGELOG
|
4
|
+
module ReverseHashMixin
|
5
|
+
def reverse
|
6
|
+
self.keys.reverse.reduce(Hash.new) do |hash, key|
|
7
|
+
hash.merge(key => self[key])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
# @param [String] path Path to your CHANGELOG file
|
5
13
|
# @raise [ArgumentError] if given path doesn't exist
|
6
14
|
# @author Jakub Stastny aka Botanicus
|
@@ -22,7 +30,7 @@ class CHANGELOG
|
|
22
30
|
# @author Jakub Stastny aka Botanicus
|
23
31
|
# @since 0.0.1
|
24
32
|
def last_version_name
|
25
|
-
self.versions.
|
33
|
+
self.versions.last
|
26
34
|
end
|
27
35
|
|
28
36
|
# @return [Array<String>, nil]
|
@@ -33,7 +41,7 @@ class CHANGELOG
|
|
33
41
|
# changelog.version_changes
|
34
42
|
# changelog.version_changes("Version 0.1")
|
35
43
|
# changelog.version_changes(/0\.1/)
|
36
|
-
def version_changes(version = self.
|
44
|
+
def version_changes(version = self.last_version_name)
|
37
45
|
self.parse[version].inject(String.new) do |buffer, line|
|
38
46
|
buffer += "[\e[32m#{version}\e[0m] #{line}\n"
|
39
47
|
end
|
@@ -76,19 +84,26 @@ class CHANGELOG
|
|
76
84
|
# @author Jakub Stastny aka Botanicus
|
77
85
|
# @since 0.0.1
|
78
86
|
def parse
|
79
|
-
@
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
@hash ||= begin
|
88
|
+
hash = __parse__.last
|
89
|
+
hash.extend(ReverseHashMixin)
|
90
|
+
hash.reverse
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
protected
|
95
|
+
def __parse__
|
96
|
+
lines = File.readlines(@path)
|
97
|
+
lines.inject([nil, Hash.new]) do |pair, line|
|
98
|
+
version, hash = pair
|
99
|
+
if line.match(/^=/)
|
100
|
+
version = line.chomp.sub(/^= /, "")
|
101
|
+
hash[version] = Array.new
|
102
|
+
elsif line.match(/^\s+\* /)
|
103
|
+
hash[version].push(line.chomp.sub(/^\s+\* /, ""))
|
104
|
+
else # skip empty lines
|
105
|
+
end
|
106
|
+
[version, hash]
|
92
107
|
end
|
93
108
|
end
|
94
109
|
end
|
data/spec/changelog_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require "changelog"
|
4
4
|
|
5
5
|
describe CHANGELOG do
|
6
6
|
before(:each) do
|
@@ -16,8 +16,8 @@ describe CHANGELOG do
|
|
16
16
|
|
17
17
|
describe "#versions" do
|
18
18
|
it "should return all versions described in the CHANGELOG" do
|
19
|
-
versions = ["Version 0.
|
20
|
-
"Version 0.1.1", "Version 0.1", "Version 0.0.1
|
19
|
+
versions = ["Version 0.0.1 Miracle Born", "Version 0.1",
|
20
|
+
"Version 0.1.1", "Version 0.1.2", "Version 0.2.0", "Version 0.2.1"]
|
21
21
|
@changelog.versions.should eql(versions)
|
22
22
|
end
|
23
23
|
end
|
@@ -54,7 +54,7 @@ describe CHANGELOG do
|
|
54
54
|
|
55
55
|
describe "#select" do
|
56
56
|
it "should return {version => [changes]} hash for all the versions matching given pattern" do
|
57
|
-
versions = ["Version 0.1
|
57
|
+
versions = ["Version 0.1", "Version 0.1.1", "Version 0.1.2"]
|
58
58
|
@changelog.select(/^Version 0.1/).keys.should eql(versions)
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -4,15 +4,15 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 5
|
8
|
+
version: "0.5"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain:
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-02-21 00:00:00 +00:00
|
16
16
|
default_executable:
|
17
17
|
dependencies: []
|
18
18
|
|
@@ -38,7 +38,7 @@ has_rdoc: true
|
|
38
38
|
homepage: http://github.com/botanicus/changelog
|
39
39
|
licenses: []
|
40
40
|
|
41
|
-
post_install_message: "[\e[32mVersion 0.
|
41
|
+
post_install_message: "[\e[32mVersion 0.5\e[0m] Ordering is solved by ReverseHashMixin.\n"
|
42
42
|
rdoc_options: []
|
43
43
|
|
44
44
|
require_paths:
|