Skip to content

Commit 91033bb

Browse files
author
Cuong Tran
committed
Make --timestamp optional by default
1 parent 8056ecf commit 91033bb

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ you can do so with a simple environment variable, instead of editing the
179179
--format
180180
--force Force new annotations even if there are no changes.
181181
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
182-
--no-timestamp Do not include an updated time in routes
182+
--timestamp Include an updated time in routes.rb
183183

184184

185185
== Sorting

bin/annotate

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ OptionParser.new do |opts|
132132
ENV['force'] = 'yes'
133133
end
134134

135-
opts.on('--no-timestamp', 'Exclude timestamp in (routes) annotation') do
136-
ENV['no_timestamp'] = 'true'
135+
opts.on('--timestamp', 'Include timestamp in (routes) annotation') do
136+
ENV['timestamp'] = 'true'
137137
end
138138

139139
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|

lib/annotate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Annotate
2222
FLAG_OPTIONS=[
2323
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
2424
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
25-
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :no_timestamp
25+
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :timestamp
2626
]
2727
OTHER_OPTIONS=[
2828
:model_dir, :ignore_columns

lib/annotate/annotate_routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def self.do_annotations(options={})
3333
routes_map.shift if(routes_map.first =~ /^\(in \//)
3434

3535
header = [
36-
"#{PREFIX}" + (options[:no_timestamp] ? "" : " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})"),
36+
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""),
3737
"#"
3838
] + routes_map.map { |line| "# #{line}".rstrip }
3939

spec/annotate/annotate_routes_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def mock_file(stubs={})
2424

2525
it "should annotate and add a newline!" do
2626
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
27-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# good line\n/)
27+
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
2828
AnnotateRoutes.do_annotations
2929
end
3030

3131
it "should not add a newline if there are empty lines" do
3232
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
33-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# good line\n/)
33+
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/)
3434
AnnotateRoutes.do_annotations
3535
end
3636

@@ -47,20 +47,20 @@ def mock_file(stubs={})
4747

4848
it "should annotate and add a newline!" do
4949
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
50-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
50+
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
5151
AnnotateRoutes.do_annotations
5252
end
5353

5454
it "should not add a newline if there are empty lines" do
5555
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
56-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
56+
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
5757
AnnotateRoutes.do_annotations
5858
end
5959

60-
it "should not add a timestamp when :no-timestamp is passed" do
61-
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
62-
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
63-
AnnotateRoutes.do_annotations :no_timestamp => true
60+
it "should add a timestamp when :timestamp is passed" do
61+
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
62+
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/)
63+
AnnotateRoutes.do_annotations :timestamp => true
6464
end
6565

6666
end
@@ -74,13 +74,13 @@ def mock_file(stubs={})
7474
end
7575

7676
it "should remove trailing annotation and trim trailing newlines, but leave leading newlines alone" do
77-
File.should_receive(:read).with("config/routes.rb").and_return("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n# == Route Map (Updated 2012-08-16 00:00)\n#\n# another good line\n# good line\n")
77+
File.should_receive(:read).with("config/routes.rb").and_return("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n# == Route Map\n#\n# another good line\n# good line\n")
7878
@mock_file.should_receive(:puts).with(/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n/)
7979
AnnotateRoutes.remove_annotations
8080
end
8181

8282
it "should remove prepended annotation and trim leading newlines, but leave trailing newlines alone" do
83-
File.should_receive(:read).with("config/routes.rb").and_return("# == Route Map (Updated 2012-08-16 00:00)\n#\n# another good line\n# good line\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n")
83+
File.should_receive(:read).with("config/routes.rb").and_return("# == Route Map\n#\n# another good line\n# good line\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n")
8484
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n\n\n\n\n\n\n\n\n\n/)
8585
AnnotateRoutes.remove_annotations
8686
end

0 commit comments

Comments
 (0)