Commit 809a29f9 by Jon Frisby

Fixing behavior with some model sub-classes, adding skip-annotations feature.

parent 70206842
== HEAD == HEAD
* Add ability to skip annotations for a model by adding
'# -*- SkipSchemaAnnotations' anywhere in the file.
* Don't show column limits for integer and boolean types. * Don't show column limits for integer and boolean types.
* Add sorting for columns and indexes. (Helpful for out-of-order migration * Add sorting for columns and indexes. (Helpful for out-of-order migration
execution!) execution!)
......
...@@ -85,6 +85,11 @@ This will produce a .rake file that will ensure annotation happens after ...@@ -85,6 +85,11 @@ This will produce a .rake file that will ensure annotation happens after
migration (but only in development mode), and provide configuration options migration (but only in development mode), and provide configuration options
you can use to tailor the output. you can use to tailor the output.
If you want to always skip annotations on a particular model, add this string
anywhere in the file:
# -*- SkipSchemaAnnotations
== OPTIONS == OPTIONS
Usage: annotate_models [options] [model_file]* Usage: annotate_models [options] [model_file]*
......
...@@ -146,6 +146,7 @@ module AnnotateModels ...@@ -146,6 +146,7 @@ module AnnotateModels
def annotate_one_file(file_name, info_block, options={}) def annotate_one_file(file_name, info_block, options={})
if File.exist?(file_name) if File.exist?(file_name)
old_content = File.read(file_name) old_content = File.read(file_name)
return false if(old_content =~ /# -\*- SkipSchemaAnnotations.*\n/)
# Ignore the Schema version line because it changes with each migration # Ignore the Schema version line because it changes with each migration
header_pattern = /(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/ header_pattern = /(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?\n)/
...@@ -269,7 +270,7 @@ module AnnotateModels ...@@ -269,7 +270,7 @@ module AnnotateModels
# in subdirectories without namespacing. # in subdirectories without namespacing.
def get_model_class(file) def get_model_class(file)
# this is for non-rails projects, which don't get Rails auto-require magic # this is for non-rails projects, which don't get Rails auto-require magic
require File.expand_path("#{model_dir}/#{file}") unless Module.const_defined?(:Rails) require File.expand_path("#{model_dir}/#{file}")
model_path = file.gsub(/\.rb$/, '') model_path = file.gsub(/\.rb$/, '')
get_loaded_model(model_path) || get_loaded_model(model_path.split('/').last) get_loaded_model(model_path) || get_loaded_model(model_path.split('/').last)
...@@ -277,9 +278,9 @@ module AnnotateModels ...@@ -277,9 +278,9 @@ module AnnotateModels
# Retrieve loaded model class by path to the file where it's supposed to be defined. # Retrieve loaded model class by path to the file where it's supposed to be defined.
def get_loaded_model(model_path) def get_loaded_model(model_path)
ObjectSpace.each_object(class << ActiveRecord::Base; self; end).detect do |c| ObjectSpace.each_object.
ActiveSupport::Inflector.underscore(c) == model_path select { |c| c.is_a?(Class) && c.ancestors.include?(ActiveRecord::Base) }.
end detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end end
# We're passed a name of things that might be # We're passed a name of things that might be
......
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