Skip to content
Browse files

Split classes in multiple files.

  • Loading branch information...
1 parent 267e990 commit b0fd4699ea96945817cf9ae710dab5ec30a294b7 @pcreux committed Aug 25, 2011
View
2 Guardfile
@@ -3,5 +3,5 @@
guard 'rspec', :version => 2 do
watch('^spec/(.*)_spec.rb')
- watch('^lib/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
+ watch('^lib/pimpmychangelog/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" }
end
View
84 lib/githubify.rb
@@ -1,84 +0,0 @@
-SEPARATOR = "<!--- The following link definitions are generated by PimpMyChangelog --->"
-
-class Githubifier
-
- attr_reader :user, :project, :changelog
-
- # @param user [String] Github user of this changelog
- # @param project [String] Github project of this changelog
- # @param changelog [String] The changelog
- def initialize(user, project, changelog)
- @user = user
- @project = project
- @changelog = changelog
- end
-
- # @return [String] The changelog with contributors and issues as link
- def better_changelog
- parsed_changelog = ChangeLogParser.new(changelog)
-
- linkify_changelog(parsed_changelog.content) + links_definitions(parsed_changelog.issues, parsed_changelog.contributors)
- end
-
- protected
-
- # @param [String] changelog
- # @return [String] The changelog with users and issues linkified.
- #
- # Example: "@pcreux closes issue #123"
- # # => "[@pcreux][] closes issue [#123][]"
- def linkify_changelog(changelog)
- changelog.
- gsub(ISSUE_NUMBER_REGEXP, '\1[#\2][]\3').
- gsub(CONTRIBUTOR_REGEXP, '\1[@\2][]\3')
- end
-
- # The following regexp ensure that the issue or contributor is
- # not wrapped between brackets (aka: is a link)
- ISSUE_NUMBER_REGEXP = /(^|[^\[])#(\d+)($|[^\]])/
- CONTRIBUTOR_REGEXP = /(^|[^\[])@(\w+)($|[^\]])/
-
- # @param [Array] issues An array of issue numbers
- # @param [Array] contributors An array of contributors github ids
- #
- # @return [String] A list of link definitions.
- def links_definitions(issues, contributors)
- return '' if issues.empty? && contributors.empty?
-
- issues_list = issues.map do |issue|
- "[##{issue}]: https://github.com/#{user}/#{project}/issues/#{issue}"
- end
-
- contributors_list = contributors.map do |contributor|
- "[@#{contributor}]: https://github.com/#{contributor}"
- end
-
- ([SEPARATOR] + issues_list + contributors_list).join("\n")
- end
-end
-
-class ChangeLogParser
- attr_reader :changelog
-
- # @param [String] changelog
- def initialize(changelog)
- @changelog = changelog
- end
-
- # @return [String] the changelog content without the link definitions
- def content
- @changelog.split(SEPARATOR).first
- end
-
- # @return [Array] ordered array of issue numbers found in the changelog
- # Example: ['12', '223', '470']
- def issues
- changelog.scan(/#(\d+)/).flatten.uniq.sort_by(&:to_i)
- end
-
- # @return [Array] ordered array of contributors found in the changelog
- # Example: ['gregbell', 'pcreux', 'samvincent']
- def contributors
- changelog.scan(/@(\w+)/).flatten.uniq.sort
- end
-end
View
2 lib/pimpmychangelog.rb
@@ -0,0 +1,2 @@
+require File.expand_path('../pimpmychangelog/parser.rb', __FILE__)
+require File.expand_path('../pimpmychangelog/pimper.rb', __FILE__)
View
27 lib/pimpmychangelog/parser.rb
@@ -0,0 +1,27 @@
+module PimpMyChangelog
+ class Parser
+ attr_reader :changelog
+
+ # @param [String] changelog
+ def initialize(changelog)
+ @changelog = changelog
+ end
+
+ # @return [String] the changelog content without the link definitions
+ def content
+ @changelog.split(Pimper::SEPARATOR).first
+ end
+
+ # @return [Array] ordered array of issue numbers found in the changelog
+ # Example: ['12', '223', '470']
+ def issues
+ changelog.scan(/#(\d+)/).flatten.uniq.sort_by(&:to_i)
+ end
+
+ # @return [Array] ordered array of contributors found in the changelog
+ # Example: ['gregbell', 'pcreux', 'samvincent']
+ def contributors
+ changelog.scan(/@(\w+)/).flatten.uniq.sort
+ end
+ end
+end
View
61 lib/pimpmychangelog/pimper.rb
@@ -0,0 +1,61 @@
+module PimpMyChangelog
+
+ class Pimper
@samvincent
samvincent added a note Aug 26, 2011

I love this class name. Lolz.

@pcreux
Owner
pcreux added a note Aug 26, 2011

SamReh liked it too. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ SEPARATOR = "<!--- The following link definitions are generated by PimpMyChangelog --->"
+
+ attr_reader :user, :project, :changelog
+
+ # @param user [String] Github user of this changelog
+ # @param project [String] Github project of this changelog
+ # @param changelog [String] The changelog
+ def initialize(user, project, changelog)
+ @user = user
+ @project = project
+ @changelog = changelog
+ end
+
+ # @return [String] The changelog with contributors and issues as link
+ def better_changelog
+ parsed_changelog = Parser.new(changelog)
+
+ linkify_changelog(parsed_changelog.content) +
+ links_definitions(parsed_changelog.issues, parsed_changelog.contributors)
+ end
+
+ protected
+
+ # @param [String] changelog
+ # @return [String] The changelog with users and issues linkified.
+ #
+ # Example: "@pcreux closes issue #123"
+ # # => "[@pcreux][] closes issue [#123][]"
+ def linkify_changelog(changelog)
+ changelog.
+ gsub(ISSUE_NUMBER_REGEXP, '\1[#\2][]\3').
+ gsub(CONTRIBUTOR_REGEXP, '\1[@\2][]\3')
+ end
+
+ # The following regexp ensure that the issue or contributor is
+ # not wrapped between brackets (aka: is a link)
+ ISSUE_NUMBER_REGEXP = /(^|[^\[])#(\d+)($|[^\]])/
+ CONTRIBUTOR_REGEXP = /(^|[^\[])@(\w+)($|[^\]])/
+
+ # @param [Array] issues An array of issue numbers
+ # @param [Array] contributors An array of contributors github ids
+ #
+ # @return [String] A list of link definitions
+ def links_definitions(issues, contributors)
+ return '' if issues.empty? && contributors.empty?
+
+ issues_list = issues.map do |issue|
+ "[##{issue}]: https://github.com/#{user}/#{project}/issues/#{issue}"
+ end
+
+ contributors_list = contributors.map do |contributor|
+ "[@#{contributor}]: https://github.com/#{contributor}"
+ end
+
+ ([SEPARATOR] + issues_list + contributors_list).join("\n")
+ end
+ end
+end
View
56 spec/parser_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe Parser do
+
+ describe "#initialize" do
+ it "should take a changelog" do
+ p = Parser.new('CHANGELOG')
+ p.changelog.should == 'CHANGELOG'
+ end
+ end
+
+ describe "#content" do
+ context "when the changelog has link definitions" do
+ let(:changelog) { <<-EOS
+# My Awesome ChangeLog
+
+This my awesome changelog.
+
+<!--- The following link definitions are generated by PimpMyChangelog --->
+#123: https://whatever
+@pcreux: https://github.com/pcreux
+EOS
+ }
+
+ it "should return the ChangeLog without the link definitions" do
+ Parser.new(changelog).content.should == <<-EOS
+# My Awesome ChangeLog
+
+This my awesome changelog.
+
+EOS
+ end
+ end # context "when the changelog has link definitions"
+
+ context "when the changelog does not have link definitions" do
+ let(:changelog) { "# My Awesome ChangeLog" }
+
+ it "should return the ChangeLog without the link definitions" do
+ Parser.new(changelog).content.should == changelog
+ end
+ end # context "when the changelog has link definitions"
+ end # describe "#content"
+
+ describe "#issues" do
+ it "should return a sorted list of unique issue numbers" do
+ Parser.new("#20 #100 #300 #20").issues.should == ['20', '100', '300']
+ end
+ end
+
+ describe "#contributors" do
+ it "should return a sorted list of unique contributors" do
+ Parser.new("@samvincent @pcreux @gregbell @pcreux").contributors.
+ should == ['gregbell', 'pcreux', 'samvincent']
+ end
+ end
+end
View
69 spec/githubify_spec.rb → spec/pimper_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../lib/githubify', __FILE__)
+require 'spec_helper'
-describe Githubifier do
+describe Pimper do
describe "#initialize" do
it "should take a github user, a github project and a changelog" do
- g = Githubifier.new('gregbell', 'activeadmin', 'ChangeLog')
+ g = Pimper.new('gregbell', 'activeadmin', 'ChangeLog')
g.user.should == 'gregbell'
g.project.should == 'activeadmin'
g.changelog.should == 'ChangeLog'
@@ -14,7 +14,7 @@
let(:user) { 'gregbell' }
let(:project) { 'activeadmin' }
- let(:better_changelog) { Githubifier.new(user, project, changelog).better_changelog }
+ let(:better_changelog) { Pimper.new(user, project, changelog).better_changelog }
subject { better_changelog }
@@ -73,7 +73,7 @@
EOS
}
- let(:better_changelog) { Githubifier.new('gregbell', 'activeadmin', changelog).better_changelog }
+ let(:better_changelog) { Pimper.new('gregbell', 'activeadmin', changelog).better_changelog }
it "should regenerate the link definition but leave the existing links alone" do
(better_changelog + "\n").should == <<-EOS
@@ -95,62 +95,3 @@
end
-describe ChangeLogParser do
-
- describe "#initialize" do
- it "should take a changelog" do
- p = ChangeLogParser.new('CHANGELOG')
- p.changelog.should == 'CHANGELOG'
- end
- end
-
- describe "#content" do
- context "when the changelog has link definitions" do
- let(:changelog) { <<-EOS
-# My Awesome ChangeLog
-
-This my awesome changelog.
-
-<!--- The following link definitions are generated by PimpMyChangelog --->
-#123: https://whatever
-@pcreux: https://github.com/pcreux
-EOS
- }
-
- it "should return the ChangeLog without the link definitions" do
- ChangeLogParser.new(changelog).content.should == <<-EOS
-# My Awesome ChangeLog
-
-This my awesome changelog.
-
-EOS
- end
- end # context "when the changelog has link definitions"
-
- context "when the changelog does not have link definitions" do
- let(:changelog) { <<-EOS
-# My Awesome ChangeLog
-
-This my awesome changelog.
-EOS
- }
-
- it "should return the ChangeLog without the link definitions" do
- ChangeLogParser.new(changelog).content.should == changelog
- end
- end # context "when the changelog has link definitions"
- end # describe "#content"
-
- describe "#issues" do
- it "should return a sorted list of unique issue numbers" do
- ChangeLogParser.new("#20 #100 #300 #20").issues.should == ['20', '100', '300']
- end
- end
-
- describe "#contributors" do
- it "should return a sorted list of unique contributors" do
- ChangeLogParser.new("@samvincent @pcreux @gregbell @pcreux").contributors.
- should == ['gregbell', 'pcreux', 'samvincent']
- end
- end
-end
View
3 spec/spec_helper.rb
@@ -0,0 +1,3 @@
+require File.expand_path('../../lib/pimpmychangelog', __FILE__)
+
+include PimpMyChangelog

0 comments on commit b0fd469

Please sign in to comment.
Something went wrong with that request. Please try again.