Skip to content

Commit 67fd10c

Browse files
author
Cuong Tran
committed
Add an option to exclude timestamp in routes, #136
1 parent ecbd5fa commit 67fd10c

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

README.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +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
182183

183184

184185
== Sorting

bin/annotate

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ 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'
137+
end
138+
135139
opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
136140
ENV['trace'] = 'yes'
137141
end

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,
25+
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :no_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} (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})",
36+
"#{PREFIX}" + (options[:no_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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def mock_file(stubs={})
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
64+
end
65+
6066
end
6167

6268
describe "When Removing Annotation" do

0 commit comments

Comments
 (0)