Skip to content
Merged
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
32 changes: 18 additions & 14 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class << self
def model_dir
@model_dir || "app/models"
end

def model_dir=(dir)
@model_dir = dir
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def get_schema_info(klass, header, options = {})
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
end
end

# Check out if we got a geometric column
# and print the type and SRID
if col.respond_to?(:geometry_type)
Expand Down Expand Up @@ -180,7 +180,7 @@ def annotate_one_file(file_name, info_block, options={})
if old_columns == new_columns && !options[:force]
false
else

# todo: figure out if we need to extract any logic from this merge chunk
# <<<<<<< HEAD
# # Replace the old schema info with the new schema info
Expand All @@ -197,7 +197,7 @@ def annotate_one_file(file_name, info_block, options={})
# Strip the old schema info, and insert new schema info.
old_content.sub!(encoding, '')
old_content.sub!(PATTERN, '')

new_content = (options[:position] || 'before').to_s == 'after' ?
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
(encoding_header + info_block + old_content)
Expand All @@ -207,7 +207,7 @@ def annotate_one_file(file_name, info_block, options={})
end
end
end

def remove_annotation_of_file(file_name)
if File.exist?(file_name)
content = File.read(file_name)
Expand Down Expand Up @@ -252,8 +252,10 @@ def annotate(klass, file, header, options={})
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
File.join(FACTORY_GIRL_TEST_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
File.join(FACTORY_GIRL_SPEC_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep these in there, so we don't break older projects. Or is this a hard deprecation?

File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
File.join(FABRICATORS_TEST_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
File.join(FABRICATORS_SPEC_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
].each do |file|
Expand Down Expand Up @@ -302,7 +304,7 @@ def get_model_files(options)
end
models
end

# Retrieve the classes belonging to the model names we're asked to process
# Check for namespaced models in subdirectories as well as models
# in subdirectories without namespacing.
Expand All @@ -320,7 +322,7 @@ def get_loaded_model(model_path)
select do |c|
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
c.ancestors.respond_to?(:include?) and # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
c.ancestors.include?(ActiveRecord::Base)
c.ancestors.include?(ActiveRecord::Base)
end.
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
end
Expand All @@ -342,9 +344,9 @@ def do_annotations(options={})
version = ActiveRecord::Migrator.current_version rescue 0
if version > 0
header << "\n# Schema version: #{version}"
end
end
end

self.model_dir = options[:model_dir] if options[:model_dir]

annotated = []
Expand Down Expand Up @@ -394,8 +396,10 @@ def remove_annotations(options={})
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
File.join(FACTORY_GIRL_TEST_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
File.join(FACTORY_GIRL_SPEC_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
File.join(FABRICATORS_TEST_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
File.join(FABRICATORS_SPEC_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
].each do |file|
Expand All @@ -405,7 +409,7 @@ def remove_annotations(options={})
end
rescue Exception => e
puts "Unable to deannotate #{file}: #{e.message}"
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
end
end
puts "Removed annotation from: #{deannotated.join(', ')}"
Expand Down