nofxx-annotate 2.2.3 → 2.2.5

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/annotate.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{annotate}
5
- s.version = "2.2.3"
5
+ s.version = "2.2.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marcos Piccinini"]
9
- s.date = %q{2008-12-26}
9
+ s.date = %q{2008-12-28}
10
10
  s.default_executable = %q{annotate}
11
11
  s.description = %q{Annotates Rails Models and Routes}
12
12
  s.email = ["x@nofxx.com"]
@@ -26,14 +26,14 @@ Gem::Specification.new do |s|
26
26
  s.specification_version = 2
27
27
 
28
28
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
- s.add_development_dependency(%q<newgem>, [">= 1.2.1"])
29
+ s.add_development_dependency(%q<newgem>, [">= 1.2.2"])
30
30
  s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
31
31
  else
32
- s.add_dependency(%q<newgem>, [">= 1.2.1"])
32
+ s.add_dependency(%q<newgem>, [">= 1.2.2"])
33
33
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
34
34
  end
35
35
  else
36
- s.add_dependency(%q<newgem>, [">= 1.2.1"])
36
+ s.add_dependency(%q<newgem>, [">= 1.2.2"])
37
37
  s.add_dependency(%q<hoe>, [">= 1.8.0"])
38
38
  end
39
39
  end
data/bin/annotate CHANGED
@@ -15,6 +15,7 @@ end.parse!
15
15
 
16
16
  begin
17
17
  Rake::Task[task].invoke
18
+ #TODO: rescue only rake error
18
19
  rescue NameError => e
19
20
  puts "Can`t find Rake. Are we in a Rails folder?"
20
21
  end
@@ -17,21 +17,22 @@
17
17
  # Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
18
18
  #
19
19
  module AnnotateRoutes
20
- PREFIX = "#== Route Info"
20
+ PREFIX = "#== Route Map"
21
21
 
22
22
  def self.do_annotate
23
23
  routes_rb = File.join("config", "routes.rb")
24
- header = PREFIX + "\n# Generated on #{Time.now}\n#"
24
+ header = PREFIX + "\n# Generated on #{Time.now.strftime("%d %b %Y %H:%M")}\n#"
25
25
  if File.exists? routes_rb
26
26
  routes_map = `rake routes`
27
27
  routes_map = routes_map.split("\n")
28
28
  routes_map.shift # remove the first line of rake routes which is just a file path
29
29
  routes_map = routes_map.inject(header){|sum, line| sum<<"\n# "<<line}
30
30
  content = File.read(routes_rb)
31
- content = content.split(/^#== Route Info.*?\n/)#, '')
31
+ content, old = content.split(/^#== Route .*?\n/)
32
32
  File.open(routes_rb, "wb") do |f|
33
- f.puts content[0] + "\n\n" + routes_map
33
+ f.puts content.sub!(/\n?\z/, "\n") + routes_map
34
34
  end
35
+ puts "Route file annotated."
35
36
  else
36
37
  puts "Can`t find routes.rb"
37
38
  end
data/lib/annotate.rb CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Annotate
5
- VERSION = '2.2.3'
5
+ VERSION = '2.2.5'
6
6
  end
7
7
 
8
8
  begin
@@ -7,24 +7,41 @@ describe AnnotateRoutes do
7
7
  @mock_file ||= mock(File, stubs)
8
8
  end
9
9
 
10
- it "should check if routes.rb exists" do
11
- File.should_receive(:join).with("config", "routes.rb").and_return(mock_file)
12
- File.should_receive(:exists?).with(@mock_file).and_return(false)
13
- AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
10
+ describe "Annotate Job" do
14
11
 
15
- AnnotateRoutes.do_annotate
16
- end
12
+ before(:each) do
13
+ File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
14
+ end
17
15
 
18
- it "should annotate!" do
19
- File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
20
- File.should_receive(:exists?).with("config/routes.rb").and_return(true)
21
- AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line")
22
- File.should_receive(:read).with("config/routes.rb").and_return("bla")
23
- File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
24
- @mock_file.should_receive(:puts).with(/bla\n\n#== Route Info\n# Generated on .*\n#\n# good line/)
16
+ it "should check if routes.rb exists" do
17
+ File.should_receive(:exists?).with("config/routes.rb").and_return(false)
18
+ AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
19
+ AnnotateRoutes.do_annotate
20
+ end
25
21
 
26
- AnnotateRoutes.do_annotate
27
- end
22
+ describe "When Annotating" do
23
+
24
+ before(:each) do
25
+ File.should_receive(:exists?).with("config/routes.rb").and_return(true)
26
+ AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line")
27
+ File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
28
+ AnnotateRoutes.should_receive(:puts).with("Route map annotated.")
29
+ end
30
+
31
+ it "should annotate and add a newline!" do
32
+ File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
33
+ @mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/)
34
+ AnnotateRoutes.do_annotate
35
+ end
28
36
 
37
+ it "should not add a newline if there are empty lines" do
38
+ File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
39
+ @mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/)
40
+ AnnotateRoutes.do_annotate
41
+ end
42
+
43
+ end
44
+
45
+ end
29
46
 
30
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nofxx-annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-26 00:00:00 -08:00
12
+ date: 2008-12-28 00:00:00 -08:00
13
13
  default_executable: annotate
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.2.1
22
+ version: 1.2.2
23
23
  version:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: hoe