Unverified Commit 846c7f8e by Andrew W. Lee Committed by GitHub

Make it possible to annotate models and routes together (#647)

Prior to this change, `Annotate.include_models?` returned the inverse of `Annotate.include_routes?`. This made it so annotating models and routes was not possible to do together. This PR adds an explicit `--models` flag and also adds it the option to `lib/generators/annotate/templates/auto_annotate_models.rake` with the default being set to `false`. Fixes #563 and undoes the bug introduced in #485.
parent 2775001d
...@@ -89,11 +89,11 @@ To annotate all your models, tests, fixtures, and factories: ...@@ -89,11 +89,11 @@ To annotate all your models, tests, fixtures, and factories:
To annotate just your models, tests, and factories: To annotate just your models, tests, and factories:
annotate --exclude fixtures annotate --models --exclude fixtures
To annotate just your models: To annotate just your models:
annotate --exclude tests,fixtures,factories,serializers annotate --models
To annotate routes.rb: To annotate routes.rb:
...@@ -184,6 +184,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -184,6 +184,7 @@ you can do so with a simple environment variable, instead of editing the
--wo, --wrapper-open STR Annotation wrapper opening. --wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing --wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes' -r, --routes Annotate routes.rb with the output of 'rake routes'
--models Annotate ActiveRecord models
-a, --active-admin Annotate active_admin models -a, --active-admin Annotate active_admin models
-v, --version Show the current version of this gem -v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation -m, --show-migration Include the migration version number in the annotation
......
...@@ -37,7 +37,7 @@ module Annotate ...@@ -37,7 +37,7 @@ module Annotate
].freeze ].freeze
OTHER_OPTIONS = [ OTHER_OPTIONS = [
:additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close, :additional_file_patterns, :ignore_columns, :skip_on_db_migrate, :wrapper_open, :wrapper_close,
:wrapper, :routes, :hide_limit_column_types, :hide_default_column_types, :wrapper, :routes, :models, :hide_limit_column_types, :hide_default_column_types,
:ignore_routes, :active_admin :ignore_routes, :active_admin
].freeze ].freeze
PATH_OPTIONS = [ PATH_OPTIONS = [
...@@ -115,7 +115,7 @@ module Annotate ...@@ -115,7 +115,7 @@ module Annotate
end end
def self.include_models? def self.include_models?
ENV['routes'] !~ TRUE_RE ENV['models'] =~ TRUE_RE
end end
def self.loaded_tasks=(val) def self.loaded_tasks=(val)
......
...@@ -123,6 +123,10 @@ module Annotate ...@@ -123,6 +123,10 @@ module Annotate
env['routes'] = 'true' env['routes'] = 'true'
end end
option_parser.on('--models', "Annotate routes.rb with the output of 'rake routes'") do
env['models'] = 'true'
end
option_parser.on('-a', '--active-admin', 'Annotate active_admin models') do option_parser.on('-a', '--active-admin', 'Annotate active_admin models') do
env['active_admin'] = 'true' env['active_admin'] = 'true'
end end
......
...@@ -9,6 +9,7 @@ if Rails.env.development? ...@@ -9,6 +9,7 @@ if Rails.env.development?
Annotate.set_defaults( Annotate.set_defaults(
'additional_file_patterns' => [], 'additional_file_patterns' => [],
'routes' => 'false', 'routes' => 'false',
'models' => 'false',
'position_in_routes' => 'before', 'position_in_routes' => 'before',
'position_in_class' => 'before', 'position_in_class' => 'before',
'position_in_test' => 'before', 'position_in_test' => 'before',
......
...@@ -222,6 +222,17 @@ module Annotate # rubocop:disable Metrics/ModuleLength ...@@ -222,6 +222,17 @@ module Annotate # rubocop:disable Metrics/ModuleLength
end end
end end
%w[--models].each do |option|
describe option do
let(:env_key) { 'models' }
let(:set_value) { 'true' }
it 'sets the ENV variable' do
expect(ENV).to receive(:[]=).with(env_key, set_value)
Parser.parse([option])
end
end
end
%w[-a --active-admin].each do |option| %w[-a --active-admin].each do |option|
describe option do describe option do
let(:env_key) { 'active_admin' } let(:env_key) { 'active_admin' }
......
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