@@ -39,7 +39,7 @@ class << self
39
39
def model_dir
40
40
@model_dir || "app/models"
41
41
end
42
-
42
+
43
43
def model_dir = ( dir )
44
44
@model_dir = dir
45
45
end
@@ -92,7 +92,7 @@ def get_schema_info(klass, header, options = {})
92
92
col_type << "(#{ col . limit } )" unless NO_LIMIT_COL_TYPES . include? ( col_type )
93
93
end
94
94
end
95
-
95
+
96
96
# Check out if we got a geometric column
97
97
# and print the type and SRID
98
98
if col . respond_to? ( :geometry_type )
@@ -180,7 +180,7 @@ def annotate_one_file(file_name, info_block, options={})
180
180
if old_columns == new_columns && !options [ :force ]
181
181
false
182
182
else
183
-
183
+
184
184
# todo: figure out if we need to extract any logic from this merge chunk
185
185
# <<<<<<< HEAD
186
186
# # Replace the old schema info with the new schema info
@@ -197,7 +197,7 @@ def annotate_one_file(file_name, info_block, options={})
197
197
# Strip the old schema info, and insert new schema info.
198
198
old_content . sub! ( encoding , '' )
199
199
old_content . sub! ( PATTERN , '' )
200
-
200
+
201
201
new_content = ( options [ :position ] || 'before' ) . to_s == 'after' ?
202
202
( encoding_header + ( old_content . rstrip + "\n \n " + info_block ) ) :
203
203
( encoding_header + info_block + old_content )
@@ -207,7 +207,7 @@ def annotate_one_file(file_name, info_block, options={})
207
207
end
208
208
end
209
209
end
210
-
210
+
211
211
def remove_annotation_of_file ( file_name )
212
212
if File . exist? ( file_name )
213
213
content = File . read ( file_name )
@@ -252,8 +252,10 @@ def annotate(klass, file, header, options={})
252
252
File . join ( EXEMPLARS_SPEC_DIR , "#{ model_name } _exemplar.rb" ) , # Object Daddy
253
253
File . join ( BLUEPRINTS_TEST_DIR , "#{ model_name } _blueprint.rb" ) , # Machinist Blueprints
254
254
File . join ( BLUEPRINTS_SPEC_DIR , "#{ model_name } _blueprint.rb" ) , # Machinist Blueprints
255
- File . join ( FACTORY_GIRL_TEST_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories
256
- File . join ( FACTORY_GIRL_SPEC_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories
255
+ File . join ( FACTORY_GIRL_TEST_DIR , "#{ klass . table_name } .rb" ) , # Factory Girl Factories (new style)
256
+ File . join ( FACTORY_GIRL_SPEC_DIR , "#{ klass . table_name } .rb" ) , # Factory Girl Factories (new style)
257
+ File . join ( FACTORY_GIRL_TEST_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories (old style)
258
+ File . join ( FACTORY_GIRL_SPEC_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories (old style)
257
259
File . join ( FABRICATORS_TEST_DIR , "#{ model_name } _fabricator.rb" ) , # Fabrication Fabricators
258
260
File . join ( FABRICATORS_SPEC_DIR , "#{ model_name } _fabricator.rb" ) , # Fabrication Fabricators
259
261
] . each do |file |
@@ -302,7 +304,7 @@ def get_model_files(options)
302
304
end
303
305
models
304
306
end
305
-
307
+
306
308
# Retrieve the classes belonging to the model names we're asked to process
307
309
# Check for namespaced models in subdirectories as well as models
308
310
# in subdirectories without namespacing.
@@ -320,7 +322,7 @@ def get_loaded_model(model_path)
320
322
select do |c |
321
323
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
322
324
c . ancestors . respond_to? ( :include? ) and # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
323
- c . ancestors . include? ( ActiveRecord ::Base )
325
+ c . ancestors . include? ( ActiveRecord ::Base )
324
326
end .
325
327
detect { |c | ActiveSupport ::Inflector . underscore ( c ) == model_path }
326
328
end
@@ -342,9 +344,9 @@ def do_annotations(options={})
342
344
version = ActiveRecord ::Migrator . current_version rescue 0
343
345
if version > 0
344
346
header << "\n # Schema version: #{ version } "
345
- end
347
+ end
346
348
end
347
-
349
+
348
350
self . model_dir = options [ :model_dir ] if options [ :model_dir ]
349
351
350
352
annotated = [ ]
@@ -394,8 +396,10 @@ def remove_annotations(options={})
394
396
File . join ( EXEMPLARS_SPEC_DIR , "#{ model_name } _exemplar.rb" ) , # Object Daddy
395
397
File . join ( BLUEPRINTS_TEST_DIR , "#{ model_name } _blueprint.rb" ) , # Machinist Blueprints
396
398
File . join ( BLUEPRINTS_SPEC_DIR , "#{ model_name } _blueprint.rb" ) , # Machinist Blueprints
397
- File . join ( FACTORY_GIRL_TEST_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories
398
- File . join ( FACTORY_GIRL_SPEC_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories
399
+ File . join ( FACTORY_GIRL_TEST_DIR , "#{ klass . table_name } .rb" ) , # Factory Girl Factories (new style)
400
+ File . join ( FACTORY_GIRL_SPEC_DIR , "#{ klass . table_name } .rb" ) , # Factory Girl Factories (new style)
401
+ File . join ( FACTORY_GIRL_TEST_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories (old style)
402
+ File . join ( FACTORY_GIRL_SPEC_DIR , "#{ model_name } _factory.rb" ) , # Factory Girl Factories (old style)
399
403
File . join ( FABRICATORS_TEST_DIR , "#{ model_name } _fabricator.rb" ) , # Fabrication Fabricators
400
404
File . join ( FABRICATORS_SPEC_DIR , "#{ model_name } _fabricator.rb" ) , # Fabrication Fabricators
401
405
] . each do |file |
@@ -405,7 +409,7 @@ def remove_annotations(options={})
405
409
end
406
410
rescue Exception => e
407
411
puts "Unable to deannotate #{ file } : #{ e . message } "
408
- puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
412
+ puts "\t " + e . backtrace . join ( "\n \t " ) if options [ :trace ]
409
413
end
410
414
end
411
415
puts "Removed annotation from: #{ deannotated . join ( ', ' ) } "
0 commit comments