Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to annotate models and routes together #647

Merged
merged 3 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ To annotate all your models, tests, fixtures, and factories:

To annotate just your models, tests, and factories:

annotate --exclude fixtures
annotate --models --exclude fixtures

To annotate just your models:

annotate --exclude tests,fixtures,factories,serializers
annotate --models

To annotate routes.rb:

Expand Down Expand Up @@ -184,6 +184,7 @@ you can do so with a simple environment variable, instead of editing the
--wo, --wrapper-open STR Annotation wrapper opening.
--wc, --wrapper-close STR Annotation wrapper closing
-r, --routes Annotate routes.rb with the output of 'rake routes'
--models Annotate ActiveRecord models
-a, --active-admin Annotate active_admin models
-v, --version Show the current version of this gem
-m, --show-migration Include the migration version number in the annotation
Expand Down
4 changes: 2 additions & 2 deletions lib/annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Annotate
].freeze
OTHER_OPTIONS = [
: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
].freeze
PATH_OPTIONS = [
Expand Down Expand Up @@ -115,7 +115,7 @@ def self.include_routes?
end

def self.include_models?
ENV['routes'] !~ TRUE_RE
ENV['models'] =~ TRUE_RE
end

def self.loaded_tasks=(val)
Expand Down
4 changes: 4 additions & 0 deletions lib/annotate/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
env['routes'] = 'true'
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
env['active_admin'] = 'true'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if Rails.env.development?
Annotate.set_defaults(
'additional_file_patterns' => [],
'routes' => 'false',
'models' => 'false',
'position_in_routes' => 'before',
'position_in_class' => 'before',
'position_in_test' => 'before',
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/annotate/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ module Annotate # rubocop:disable Metrics/ModuleLength
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|
describe option do
let(:env_key) { 'active_admin' }
Expand Down