Commit 64b1a343 by Cuong Tran

Merge pull request #315 from mintuhouse/feature_ignore_routes_develop

Add :ignore_routes option to skip routes which should not be annotated based on regex
parents 25b6f3d6 7b5d20d4
...@@ -178,6 +178,10 @@ OptionParser.new do |opts| ...@@ -178,6 +178,10 @@ OptionParser.new do |opts|
ENV['ignore_columns'] = regex ENV['ignore_columns'] = regex
end end
opts.on('--ignore-routes REGEX', "don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'`" ) do |regex|
ENV['ignore_routes'] = regex
end
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| 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|
ENV['hide_limit_column_types'] = "#{values}" ENV['hide_limit_column_types'] = "#{values}"
end end
......
...@@ -31,7 +31,7 @@ module Annotate ...@@ -31,7 +31,7 @@ module Annotate
] ]
OTHER_OPTIONS=[ OTHER_OPTIONS=[
:ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :wrapper, :routes,
:hide_limit_column_types, :hide_limit_column_types, :ignore_routes
] ]
PATH_OPTIONS=[ PATH_OPTIONS=[
:require, :model_dir, :root_dir :require, :model_dir, :root_dir
......
...@@ -32,6 +32,10 @@ module AnnotateRoutes ...@@ -32,6 +32,10 @@ module AnnotateRoutes
# keep the line around. # keep the line around.
routes_map.shift if(routes_map.first =~ /^\(in \//) routes_map.shift if(routes_map.first =~ /^\(in \//)
# Skip routes which match given regex
# Note: it matches the complete line (route_name, path, controller/action)
routes_map.reject!{|line| line.match(/#{options[:ignore_routes]}/)} if options[:ignore_routes]
header = [ header = [
"#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""), "#{PREFIX}" + (options[:timestamp] ? " (Updated #{Time.now.strftime("%Y-%m-%d %H:%M")})" : ""),
"#" "#"
......
...@@ -29,6 +29,7 @@ if Rails.env.development? ...@@ -29,6 +29,7 @@ if Rails.env.development?
'exclude_helpers' => 'false', 'exclude_helpers' => 'false',
'ignore_model_sub_dir' => 'false', 'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil, 'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false', 'ignore_unknown_models' => 'false',
'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(',') %>', 'hide_limit_column_types' => '<%= AnnotateModels::NO_LIMIT_COL_TYPES.join(',') %>',
'skip_on_db_migrate' => 'false', 'skip_on_db_migrate' => 'false',
......
...@@ -42,6 +42,7 @@ task :annotate_models => :environment do ...@@ -42,6 +42,7 @@ task :annotate_models => :environment do
options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper']) options[:wrapper_open] = Annotate.fallback(ENV['wrapper_open'], ENV['wrapper'])
options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper']) options[:wrapper_close] = Annotate.fallback(ENV['wrapper_close'], ENV['wrapper'])
options[:ignore_columns] = ENV.fetch('ignore_columns', nil) options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
options[:ignore_routes] = ENV.fetch('ignore_routes', nil)
AnnotateModels.do_annotations(options) AnnotateModels.do_annotations(options)
end end
......
...@@ -6,6 +6,7 @@ task :annotate_routes => :environment do ...@@ -6,6 +6,7 @@ task :annotate_routes => :environment do
options={} options={}
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before') ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position']) options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
options[:ignore_routes] = Annotate.fallback(ENV['ignore_routes'], nil)
options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:require] = ENV['require'] ? ENV['require'].split(',') : []
AnnotateRoutes.do_annotations(options) AnnotateRoutes.do_annotations(options)
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment