changelog 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/changelog.rb ADDED
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+
3
+ class CHANGELOG
4
+ # @param [String] path Path to your CHANGELOG file
5
+ # @raise [ArgumentError] if given path doesn't exist
6
+ # @author Jakub Stastny aka Botanicus
7
+ # @since 0.0.1
8
+ def initialize(path = "CHANGELOG")
9
+ raise ArgumentError, "Path '#{path}' doesn't exist!" unless File.exist?(path)
10
+ @path = path
11
+ end
12
+
13
+ # @return [Array<String>] List of all the available versions
14
+ # @author Jakub Stastny aka Botanicus
15
+ # @since 0.0.1
16
+ def versions
17
+ self.parse.keys
18
+ end
19
+
20
+ # @return [String, nil]
21
+ # Name of the last available version or nil if the changelog is empty
22
+ # @author Jakub Stastny aka Botanicus
23
+ # @since 0.0.1
24
+ def last_version_name
25
+ self.versions.last
26
+ end
27
+
28
+ # @return [Array<String>, nil]
29
+ # List of changes in the last version or nil if the changelog is empty
30
+ # @author Jakub Stastny aka Botanicus
31
+ # @since 0.0.1
32
+ def last_version_changes
33
+ self.parse[self.versions.last]
34
+ end
35
+
36
+ # @param [String, Regexp] version Full name of the version or pattern matching the version.
37
+ # @raise [StandardError] if pattern matched more than one version
38
+ # @return [Array<String>, nil]
39
+ # List of changes in the given version or nil if given version doesn't exist
40
+ # @example changelog["Version 0.1"]
41
+ # @author Jakub Stastny aka Botanicus
42
+ # @since 0.0.1
43
+ def [](version)
44
+ if version.is_a?(String)
45
+ self.parse[version]
46
+ else
47
+ versions = self.select(version).keys
48
+ if versions.length > 1
49
+ raise StandardError, "More than one version was matched: #{versions.inspect}"
50
+ elsif versions.empty?
51
+ return nil
52
+ else
53
+ self[versions.first]
54
+ end
55
+ end
56
+ end
57
+
58
+ # @param [String, Regexp] version Pattern we want to match in version.
59
+ # @return [Hash] Hash of `{version => changes}` for matched versions.
60
+ # @example changelog.select(/^Version 0.1.\d+$/)
61
+ # @author Jakub Stastny aka Botanicus
62
+ # @since 0.0.1
63
+ def select(pattern)
64
+ self.parse.select do |version, changes|
65
+ version.match(pattern)
66
+ end
67
+ end
68
+
69
+ # @return [Hash] Hash of `{version => changes}` for the whole changelog.
70
+ # @author Jakub Stastny aka Botanicus
71
+ # @since 0.0.1
72
+ def parse
73
+ @result ||= begin
74
+ lines = File.readlines(@path)
75
+ lines.inject([nil, Hash.new]) do |pair, line|
76
+ version, hash = pair
77
+ if line.match(/^=/)
78
+ version = line.chomp.sub(/^= /, "")
79
+ hash[version] = Array.new
80
+ elsif line.match(/^\s+\* /)
81
+ hash[version].push(line.chomp.sub(/^\s+\* /, ""))
82
+ else # skip empty lines
83
+ end
84
+ [version, hash]
85
+ end.last
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "../lib/changelog"
4
+
5
+ describe CHANGELOG do
6
+ before(:each) do
7
+ path = File.join(File.dirname(__FILE__), "data.txt")
8
+ @changelog = CHANGELOG.new(path)
9
+ end
10
+
11
+ describe ".new" do
12
+ it "should raise ArgumentError if given path doesn't exist" do
13
+ lambda { CHANGELOG.new("/a/b/c/d") }.should raise_error(ArgumentError)
14
+ end
15
+ end
16
+
17
+ describe "#versions" do
18
+ it "should returns all versions described in the CHANGELOG" do
19
+ versions = ["Version 0.0.1 Miracle Born",
20
+ "Version 0.1", "Version 0.1.1", "Version 0.1.2",
21
+ "Version 0.2.0", "Version 0.2.1"]
22
+ @changelog.versions.should eql(versions)
23
+ end
24
+ end
25
+
26
+ describe "#last_version_name" do
27
+ it "should returns name of the last version" do
28
+ @changelog.last_version_name.should eql("Version 0.2.1")
29
+ end
30
+ end
31
+
32
+ describe "#last_version_changes" do
33
+ it "should returns changes in the last version" do
34
+ @changelog.last_version_changes.should eql(["Cucumber Integration"])
35
+ end
36
+ end
37
+
38
+ describe "#[]" do
39
+ it "should returns changes for given version" do
40
+ @changelog["Version 0.2.1"].should eql(["Cucumber Integration"])
41
+ end
42
+
43
+ it "should returns changes for given pattern if only version is matched" do
44
+ @changelog[/Version 0.2.[12]/].should eql(["Cucumber Integration"])
45
+ end
46
+
47
+ it "should raise StandardError if more than one version is matched" do
48
+ lambda { @changelog[/Version 0.2.\d/] }.should raise_error(StandardError)
49
+ end
50
+ end
51
+
52
+ describe "#select" do
53
+ it "should be able to returns {version => [changes]} hash for all the versions matching given pattern" do
54
+ versions = ["Version 0.1", "Version 0.1.1", "Version 0.1.2"]
55
+ @changelog.select(/^Version 0.1/).keys.should eql(versions)
56
+ end
57
+ end
58
+
59
+ describe "#parse" do
60
+ it "should be able to parse CHANGELOG to {version => [changes]}" do
61
+ @changelog.parse.each do |key, value|
62
+ key.should be_kind_of(String)
63
+ value.should be_kind_of(Array)
64
+ end
65
+ end
66
+ end
67
+ end
data/spec/data.txt ADDED
@@ -0,0 +1,27 @@
1
+ = Version 0.0.1 Miracle Born
2
+ * Just basics
3
+
4
+ = Version 0.1
5
+ * [FEATURE] environments support
6
+ * [SPECS] All specs passing
7
+ * SimpleTemplater, RubyExts & CLI
8
+ * [FEATURE] Bundler Support
9
+ * [FEATURE] Rack-mount support
10
+
11
+ = Version 0.1.1
12
+ * Tilt support
13
+ * Reworked generic views
14
+ * ImplicitRendering and ExplicitRendering mixins for using locals
15
+ vs. rendering in context of current controller instance
16
+
17
+ = Version 0.1.2
18
+ * Sequel support
19
+ * Project generator renamed to stack generator
20
+ * Removed app and bigapp generators
21
+
22
+ = Version 0.2.0
23
+ * Template helpers can work with paths relative to current template via ./path.html resp. ../path.html. All other paths are relative to the template paths.
24
+ * Use simple-logger as a default logger or standar logger if the simple-logger isn't installed.
25
+
26
+ = Version 0.2.1
27
+ * Cucumber Integration
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: changelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ date: 2009-12-25 00:00:00 +00:00
12
+ default_executable:
13
+ dependencies: []
14
+
15
+ description: ""
16
+ email: knava.bestvinensis@gmail.com
17
+ executables: []
18
+
19
+ extensions: []
20
+
21
+ extra_rdoc_files: []
22
+
23
+ files:
24
+ - lib/changelog.rb
25
+ - spec/changelog_spec.rb
26
+ - spec/data.txt
27
+ - spec/spec.opts
28
+ has_rdoc: true
29
+ homepage: http://github.com/botanicus/changelog
30
+ licenses: []
31
+
32
+ post_install_message: |-
33
+ === Changes in the last version of CHANGELOG ===
34
+ - Basic functionality
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project: changelog
54
+ rubygems_version: 1.3.5
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Simple CHANGELOG parser
58
+ test_files: []
59
+