railslog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +31 -0
- data/Rakefile +13 -0
- data/lib/railslog.rb +107 -0
- data/lib/railslog/version.rb +3 -0
- data/railslog.gemspec +23 -0
- data/test/test_helper.rb +3 -0
- data/test/test_railslog.rb +203 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Railslog
|
2
|
+
|
3
|
+
API for working with Rails CHANGELOG files. It grabs Rails CHANGELOGs from teh githubs and parses it to give you a Changelog object which has many Releases, which have many Entries.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install railslog
|
8
|
+
|
9
|
+
## Use
|
10
|
+
|
11
|
+
require 'railslog'
|
12
|
+
|
13
|
+
changelog = Railslog.fetch('activerecord') # => <Railslog::Changelog releases:77>
|
14
|
+
|
15
|
+
release = changelog.releases[1] # => <Railslog::Release version:3.0.7 date:2011-04-18>
|
16
|
+
release.date # => #<Date: 2011-04-18 (4911339/2,0,2299161)>
|
17
|
+
|
18
|
+
entry = release.entries.first # => <Railslog::Entry author:Durran Jordan text:Destroying records via nes...>
|
19
|
+
entry.author # => "Durran Jordan"
|
20
|
+
entry.text # => "Destroying records via nested attributes works independent of reject_if LH #6006 [Durran Jordan]\n"
|
21
|
+
|
22
|
+
## License
|
23
|
+
|
24
|
+
Copyright © 2011 Maxim Chernyak
|
25
|
+
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
27
|
+
|
28
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
+
|
data/Rakefile
ADDED
data/lib/railslog.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module Railslog
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def fetch(package)
|
9
|
+
Changelog.new(open("https://github.com/rails/rails/raw/master/#{package}/CHANGELOG").read)
|
10
|
+
end
|
11
|
+
|
12
|
+
module Helper
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def normalize(text)
|
16
|
+
text.strip.gsub(/(?:^\s*\*|\s*\*$)/, '').strip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Changelog
|
21
|
+
attr_reader :releases
|
22
|
+
|
23
|
+
def initialize(text)
|
24
|
+
@releases = []
|
25
|
+
|
26
|
+
current_release = nil
|
27
|
+
current_entry = nil
|
28
|
+
|
29
|
+
text.each_line do |line|
|
30
|
+
if Release.recognize?(line)
|
31
|
+
current_release = Release.new(line)
|
32
|
+
@releases << current_release
|
33
|
+
elsif Entry.recognize?(line)
|
34
|
+
current_entry = Entry.new(line)
|
35
|
+
current_release ||= Release.new('Unreleased')
|
36
|
+
current_release.add_entry(current_entry)
|
37
|
+
elsif !current_entry.nil?
|
38
|
+
current_entry.add_line(line)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"<#{self.class} releases:#{@releases.size}>"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Release
|
49
|
+
attr_reader :title, :version, :date, :entries
|
50
|
+
|
51
|
+
def self.recognize?(line)
|
52
|
+
line =~ /^\*\S/
|
53
|
+
end
|
54
|
+
|
55
|
+
def initialize(release_title)
|
56
|
+
@title = Helper.normalize(release_title)
|
57
|
+
@version = @title[/\d+\.\d+(?:\.\d+)?/]
|
58
|
+
@date = Date.parse(@title[/\(([^\)]+)\)/, 1]) rescue nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_entry(entry)
|
62
|
+
@entries ||= []
|
63
|
+
@entries << entry
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
"<#{self.class} version:#{@version} date:#{@date}>"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Entry
|
72
|
+
attr_reader :text, :author
|
73
|
+
|
74
|
+
def self.recognize?(line)
|
75
|
+
line =~ /^\*\s+/
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize(entry_text)
|
79
|
+
@text = Helper.normalize(entry_text)
|
80
|
+
@author = parse_author(entry_text)
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_line(text)
|
84
|
+
text.gsub!(/[\r\n]/, '')
|
85
|
+
@text << "\n#{text}"
|
86
|
+
@author = parse_author(text) || @author
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
"<#{self.class} author:#{@author} text:#{truncated_text}>"
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
def parse_author(line)
|
95
|
+
line[/\[([^#\:\?]+)\][^\]]*$/, 1].strip rescue nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def truncated_text
|
99
|
+
if @text.size > 30
|
100
|
+
"#{@text[0, 26]}..."
|
101
|
+
else
|
102
|
+
@text
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/railslog.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "railslog/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "railslog"
|
7
|
+
s.version = Railslog::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Maxim Chernyak"]
|
10
|
+
s.email = ["max@bitsonnet.com"]
|
11
|
+
s.homepage = "http://github.com/maxim/railslog"
|
12
|
+
s.summary = %q{A simple client for Rails CHANGELOG files stored on github.}
|
13
|
+
s.description = %q{Provides a convenient API for accessing Rails CHANGELOG files.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "railslog"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency 'turn'
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
module Railslog
|
5
|
+
|
6
|
+
class TestChangelog < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@changelog = Changelog.new <<-TEXT
|
9
|
+
*1.3.2* (February 5th, 2007)
|
10
|
+
|
11
|
+
* Deprecate server_settings renaming it to smtp_settings, add sendmail_settings to allow you to override the arguments to and location of the sendmail executable. [Michael Koziarski]
|
12
|
+
|
13
|
+
|
14
|
+
*1.3.1* (January 16th, 2007)
|
15
|
+
|
16
|
+
* Depend on Action Pack 1.13.1
|
17
|
+
|
18
|
+
|
19
|
+
*1.3.0* (January 16th, 2007)
|
20
|
+
|
21
|
+
* Make mime version default to 1.0. closes #2323 [ror@andreas-s.net]
|
22
|
+
|
23
|
+
* Make sure quoted-printable text is decoded correctly when only portions of the text are encoded. closes #3154. [jon@siliconcircus.com]
|
24
|
+
|
25
|
+
* Make sure DOS newlines in quoted-printable text are normalized to unix newlines before unquoting. closes #4166 and #4452. [Jamis Buck]
|
26
|
+
|
27
|
+
foo bar baz
|
28
|
+
testing multiline entry
|
29
|
+
|
30
|
+
* Fixed that iconv decoding should catch InvalidEncoding #3153 [jon@siliconcircus.com]
|
31
|
+
TEXT
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_parses_releases
|
35
|
+
assert_equal 3, @changelog.releases.size
|
36
|
+
assert_equal 1, @changelog.releases[0].entries.size
|
37
|
+
assert_equal 1, @changelog.releases[1].entries.size
|
38
|
+
assert_equal 4, @changelog.releases[2].entries.size
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_returns_pretty_to_s
|
42
|
+
assert_equal '<Railslog::Changelog releases:3>', @changelog.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TestRelease < Test::Unit::TestCase
|
47
|
+
def setup
|
48
|
+
@release = Release.new('*Rails 3.0.4 (February 8, 2011)*')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_normalizes_release_title
|
52
|
+
assert_equal 'Rails 3.0.4 (February 8, 2011)', @release.title
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_parses_version_from_release_title
|
56
|
+
assert_equal '3.0.4', @release.version
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_parses_date_from_release_title
|
60
|
+
assert_equal Date.parse('2011-02-08'), @release.date
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_sets_date_to_nil_if_cant_parse
|
64
|
+
assert_nil Release.new('*Rails 3.0.4*').date
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_maintains_array_of_entries
|
68
|
+
@release.add_entry(entry = Entry.new('foo'))
|
69
|
+
assert_includes @release.entries, entry
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_recognizes_a_release_line
|
73
|
+
assert Release.recognize?('*Rails 3.0.4 (February 8, 2011)*')
|
74
|
+
assert Release.recognize?('*1.3.1* (January 16th, 2007)')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_does_not_recognize_an_entry_line
|
78
|
+
refute Release.recognize?('* Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0 [Santiago Pastorino]')
|
79
|
+
refute Release.recognize?('* Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_returns_pretty_to_s
|
83
|
+
assert_equal '<Railslog::Release version:3.0.4 date:2011-02-08>', @release.to_s
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class TestEntry < Test::Unit::TestCase
|
88
|
+
def setup
|
89
|
+
@entry = Entry.new('* Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0 [Santiago Pastorino]')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_normalizes_entry_text
|
93
|
+
assert_equal 'Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0 [Santiago Pastorino]', @entry.text
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_parses_entry_author
|
97
|
+
assert_equal 'Santiago Pastorino', @entry.author
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_parses_entry_author_in_another_line
|
101
|
+
@entry.add_line('[foo bar]')
|
102
|
+
assert_equal 'foo bar', @entry.author
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_sets_author_to_nil_if_missing
|
106
|
+
entry = Entry.new('* Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0 ')
|
107
|
+
assert_nil entry.author
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_recognizes_an_entry_start_line
|
111
|
+
assert Entry.recognize?('* foobar')
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_does_not_recognize_a_release_line
|
115
|
+
refute Entry.recognize?('*1.3.1* (January 16th, 2007)')
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_does_not_recognize_an_entry_body_line
|
119
|
+
refute Entry.recognize?(' def iso_charset(recipient')
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_adds_line_to_entry
|
123
|
+
@entry.add_line('foobar')
|
124
|
+
assert_equal <<-TEXT.strip, @entry.text
|
125
|
+
Don\'t allow i18n to change the minor version, version now set to ~> 0.5.0 [Santiago Pastorino]
|
126
|
+
foobar
|
127
|
+
TEXT
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_returns_pretty_to_s
|
131
|
+
assert_equal '<Railslog::Entry author:Santiago Pastorino text:Don\'t allow i18n to change...>', @entry.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_normalizes_multiline_entry_text
|
135
|
+
@entry = Entry.new <<-TEXT
|
136
|
+
* Added support for charsets for both subject and body. The default charset is now UTF-8 #673 [Jamis Buck]. Examples:
|
137
|
+
|
138
|
+
def iso_charset(recipient)
|
139
|
+
@recipients = recipient
|
140
|
+
@subject = "testing iso charsets"
|
141
|
+
@from = "system@loudthinking.com"
|
142
|
+
@body = "Nothing to see here."
|
143
|
+
@charset = "iso-8859-1"
|
144
|
+
end
|
145
|
+
|
146
|
+
def unencoded_subject(recipient)
|
147
|
+
@recipients = recipient
|
148
|
+
@subject = "testing unencoded subject"
|
149
|
+
@from = "system@loudthinking.com"
|
150
|
+
@body = "Nothing to see here."
|
151
|
+
@encode_subject = false
|
152
|
+
@charset = "iso-8859-1"
|
153
|
+
end
|
154
|
+
TEXT
|
155
|
+
|
156
|
+
assert_equal <<-TEXT.strip, @entry.text
|
157
|
+
Added support for charsets for both subject and body. The default charset is now UTF-8 #673 [Jamis Buck]. Examples:
|
158
|
+
|
159
|
+
def iso_charset(recipient)
|
160
|
+
@recipients = recipient
|
161
|
+
@subject = "testing iso charsets"
|
162
|
+
@from = "system@loudthinking.com"
|
163
|
+
@body = "Nothing to see here."
|
164
|
+
@charset = "iso-8859-1"
|
165
|
+
end
|
166
|
+
|
167
|
+
def unencoded_subject(recipient)
|
168
|
+
@recipients = recipient
|
169
|
+
@subject = "testing unencoded subject"
|
170
|
+
@from = "system@loudthinking.com"
|
171
|
+
@body = "Nothing to see here."
|
172
|
+
@encode_subject = false
|
173
|
+
@charset = "iso-8859-1"
|
174
|
+
end
|
175
|
+
TEXT
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_parses_multiline_entry_author
|
179
|
+
@entry = Entry.new <<-TEXT
|
180
|
+
* Added support for charsets for both subject and body. The default charset is now UTF-8 #673 [Jamis Buck]. Examples:
|
181
|
+
|
182
|
+
def iso_charset(recipient)
|
183
|
+
@recipients = recipient
|
184
|
+
@subject = "testing iso charsets"
|
185
|
+
@from = "system@loudthinking.com"
|
186
|
+
@body = "Nothing to see here."
|
187
|
+
@charset = "iso-8859-1"
|
188
|
+
end
|
189
|
+
|
190
|
+
def unencoded_subject(recipient)
|
191
|
+
@recipients = recipient
|
192
|
+
@subject = "testing unencoded subject"
|
193
|
+
@from = "system@loudthinking.com"
|
194
|
+
@body = "Nothing to see here."
|
195
|
+
@encode_subject = false
|
196
|
+
@charset = "iso-8859-1"
|
197
|
+
end
|
198
|
+
TEXT
|
199
|
+
|
200
|
+
assert_equal 'Jamis Buck', @entry.author
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: railslog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Maxim Chernyak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-24 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: turn
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description: Provides a convenient API for accessing Rails CHANGELOG files.
|
28
|
+
email:
|
29
|
+
- max@bitsonnet.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/railslog.rb
|
42
|
+
- lib/railslog/version.rb
|
43
|
+
- railslog.gemspec
|
44
|
+
- test/test_helper.rb
|
45
|
+
- test/test_railslog.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/maxim/railslog
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: railslog
|
70
|
+
rubygems_version: 1.6.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: A simple client for Rails CHANGELOG files stored on github.
|
74
|
+
test_files:
|
75
|
+
- test/test_helper.rb
|
76
|
+
- test/test_railslog.rb
|