mafernando / Git-Example

MIT License
1 stars 0 forks source link

Annotate #3

Open mafernando opened 9 years ago

mafernando commented 9 years ago

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 unless
end