Skip to content

Commit 463cdc3

Browse files
author
Hasan Kumar Reddy A
committed
Add ignore_routes option
1 parent 0b05456 commit 463cdc3

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed

bin/annotate

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ OptionParser.new do |opts|
178178
ENV['ignore_columns'] = regex
179179
end
180180

181+
opts.on('-I', '--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`" ) do |regex|
182+
ENV['ignore_routes'] = regex
183+
end
184+
181185
opts.on('--hide-limit-column-types VALUES', "don't show limit for given column types, separated by comas (i.e., `integer,boolean,text`)" ) do |values|
182186
ENV['hide_limit_column_types'] = "#{values}"
183187
end

lib/annotate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Annotate
3131
]
3232
OTHER_OPTIONS=[
3333
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes,
34-
:hide_limit_column_types,
34+
:hide_limit_column_types, :ignore_routes
3535
]
3636
PATH_OPTIONS=[
3737
:require, :model_dir, :root_dir

lib/annotate/annotate_routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def self.do_annotations(options={})
3232
# keep the line around.
3333
routes_map.shift if(routes_map.first =~ /^\(in \//)
3434

35+
# Skip routes which match given regex
36+
# Note: it matches the complete line (route_name, path, controller/action)
37+
routes_map.reject!{|line| line.match(/#{options[:ignore_routes]}/)} if options[:ignore_routes]
38+
3539
header = [
3640
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""),
3741
"#"

lib/generators/annotate/templates/auto_annotate_models.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if Rails.env.development?
2929
'exclude_helpers' => 'false',
3030
'ignore_model_sub_dir' => 'false',
3131
'ignore_columns' => nil,
32+
'ignore_routes' => nil,
3233
'ignore_unknown_models' => 'false',
3334
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(',') %>',
3435
'skip_on_db_migrate' => 'false',

lib/tasks/annotate_models.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ task :annotate_models => :environment do
4242
options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper'])
4343
options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper'])
4444
options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
45+
options[:ignore_routes] = ENV.fetch('ignore_routes', nil)
4546

4647
AnnotateModels.do_annotations(options)
4748
end

lib/tasks/annotate_routes.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ task :annotate_routes => :environment do
66
options={}
77
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
88
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
9+
options[:ignore_routes] = Annotate.fallback(ENV['ignore_routes'], nil)
910
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
1011
AnnotateRoutes.do_annotations(options)
1112
end

0 commit comments

Comments
 (0)