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

Check if model has skip tag in annotate_model_file #243

Merged
merged 1 commit into from Apr 10, 2015

Conversation

mafernando
Copy link
Contributor

Potentially addresses issue# #167
Annotate_model_file is called automatically on all files in models directory and does not check if model contains SkipSchemaAnnotations tag.

Potentially addresses issue# ctran#167
Annotate_model_file is called automatically on all files in models directory and does not check if model contains SkipSchemaAnnotations tag.
@mafernando
Copy link
Contributor Author

Hi @ctran - In my scenario, I have a model file (more of an api wrapper) which doesn't have an actual DB table associated with it. I tried adding the # -*- SkipSchemaAnnotations tag to it, but annotate sill generates the following error message with rake db:migrate:

Unable to annotate app/models/client.rb: cannot load a model from app/models/client.rb

I attached a debugger on AnnotateModels.do_annotations(options) and traced through to annotate_models.rb:do_annotations > annotate_models.rb:annoatate_model_file and noticed that annotate checks if klass.table_exists? when it is iterating through the list of model files to annotate and throws an error if it does not exist. This error is thrown before the actual annotate method is called, so the skip tag check that would be invoked in annotate_one_file does not get called.

In summary, I'm suggesting that a skip tag check be added to annotate_model_file so that annotate checks to see if the model file has a skip tag prior to checking if its table exists which will cause an error to be thrown as it currently is.

Here is the auto_annotate_models.rake file that I am using with my app.

# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
  task :set_annotation_options do
    # You can override any of these by setting an environment variable of the
    # same name.
    Annotate.set_defaults(
      'position_in_routes'   => 'before',
      'position_in_class'    => 'before',
      'position_in_test'     => 'before',
      'position_in_fixture'  => 'before',
      'position_in_factory'  => 'before',
      'show_indexes'         => 'true',
      'simple_indexes'       => 'false',
      'model_dir'            => 'app/models',
      'include_version'      => 'false',
      'require'              => '',
      'exclude_tests'        => 'false',
      'exclude_fixtures'     => 'false',
      'exclude_factories'    => 'false',
      'ignore_model_sub_dir' => 'true',
      'skip_on_db_migrate'   => 'false',
      'format_bare'          => 'true',
      'format_rdoc'          => 'false',
      'format_markdown'      => 'false',
      'sort'                 => 'false',
      'force'                => 'false',
      'trace'                => 'false'
    )
  end

  Annotate.load_tasks
end

ctran added a commit that referenced this pull request Apr 10, 2015
Check if model has skip tag in annotate_model_file
@ctran ctran merged commit 8057cd5 into ctran:develop Apr 10, 2015
@ctran ctran added this to the v2.6.9 milestone Apr 10, 2015
@ctran ctran added the bug label Apr 10, 2015
@ctran ctran self-assigned this Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants