Skip to content

Commit

Permalink
Add an option to exclude timestamp in routes, #136
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Tran committed Feb 26, 2014
1 parent ecbd5fa commit 67fd10c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.rdoc
Expand Up @@ -179,6 +179,7 @@ you can do so with a simple environment variable, instead of editing the
--format
--force Force new annotations even if there are no changes.
--trace If unable to annotate a file, print the full stack trace, not just the exception message.
--no-timestamp Do not include an updated time in routes


== Sorting
Expand Down
4 changes: 4 additions & 0 deletions bin/annotate
Expand Up @@ -132,6 +132,10 @@ OptionParser.new do |opts|
ENV['force'] = 'yes'
end

opts.on('--no-timestamp', 'Exclude timestamp in (routes) annotation') do
ENV['no_timestamp'] = 'true'
end

opts.on('--trace', 'If unable to annotate a file, print the full stack trace, not just the exception message.') do |value|
ENV['trace'] = 'yes'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate.rb
Expand Up @@ -22,7 +22,7 @@ module Annotate
FLAG_OPTIONS=[
:show_indexes, :simple_indexes, :include_version, :exclude_tests,
:exclude_fixtures, :exclude_factories, :ignore_model_sub_dir,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace,
:format_bare, :format_rdoc, :format_markdown, :sort, :force, :trace, :no_timestamp
]
OTHER_OPTIONS=[
:model_dir, :ignore_columns
Expand Down
2 changes: 1 addition & 1 deletion lib/annotate/annotate_routes.rb
Expand Up @@ -33,7 +33,7 @@ def self.do_annotations(options={})
routes_map.shift if(routes_map.first =~ /^\(in \//)

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

Expand Down
6 changes: 6 additions & 0 deletions spec/annotate/annotate_routes_spec.rb
Expand Up @@ -57,6 +57,12 @@ def mock_file(stubs={})
AnnotateRoutes.do_annotations
end

it "should not add a timestamp when :no-timestamp is passed" do
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/)
AnnotateRoutes.do_annotations :no_timestamp => true
end

end

describe "When Removing Annotation" do
Expand Down

0 comments on commit 67fd10c

Please sign in to comment.