|
1 | 1 | require 'bigdecimal'
|
2 |
| -require 'annotate/file_patterns' |
3 | 2 |
|
4 | 3 | module AnnotateModels
|
5 | 4 | TRUE_RE = /^(true|t|yes|y|1)$/i
|
@@ -78,6 +77,73 @@ def root_dir
|
78 | 77 |
|
79 | 78 | attr_writer :root_dir
|
80 | 79 |
|
| 80 | + def test_files(root_directory) |
| 81 | + [ |
| 82 | + File.join(root_directory, UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"), |
| 83 | + File.join(root_directory, MODEL_TEST_DIR, "%MODEL_NAME%_test.rb"), |
| 84 | + File.join(root_directory, SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb") |
| 85 | + ] |
| 86 | + end |
| 87 | + |
| 88 | + def fixture_files(root_directory) |
| 89 | + [ |
| 90 | + File.join(root_directory, FIXTURE_TEST_DIR, "%TABLE_NAME%.yml"), |
| 91 | + File.join(root_directory, FIXTURE_SPEC_DIR, "%TABLE_NAME%.yml"), |
| 92 | + File.join(root_directory, FIXTURE_TEST_DIR, "%PLURALIZED_MODEL_NAME%.yml"), |
| 93 | + File.join(root_directory, FIXTURE_SPEC_DIR, "%PLURALIZED_MODEL_NAME%.yml") |
| 94 | + ] |
| 95 | + end |
| 96 | + |
| 97 | + def scaffold_files(root_directory) |
| 98 | + [ |
| 99 | + File.join(root_directory, CONTROLLER_TEST_DIR, "%PLURALIZED_MODEL_NAME%_controller_test.rb"), |
| 100 | + File.join(root_directory, CONTROLLER_SPEC_DIR, "%PLURALIZED_MODEL_NAME%_controller_spec.rb"), |
| 101 | + File.join(root_directory, REQUEST_SPEC_DIR, "%PLURALIZED_MODEL_NAME%_spec.rb"), |
| 102 | + File.join(root_directory, ROUTING_SPEC_DIR, "%PLURALIZED_MODEL_NAME%_routing_spec.rb") |
| 103 | + ] |
| 104 | + end |
| 105 | + |
| 106 | + def factory_files(root_directory) |
| 107 | + [ |
| 108 | + File.join(root_directory, EXEMPLARS_TEST_DIR, "%MODEL_NAME%_exemplar.rb"), |
| 109 | + File.join(root_directory, EXEMPLARS_SPEC_DIR, "%MODEL_NAME%_exemplar.rb"), |
| 110 | + File.join(root_directory, BLUEPRINTS_TEST_DIR, "%MODEL_NAME%_blueprint.rb"), |
| 111 | + File.join(root_directory, BLUEPRINTS_SPEC_DIR, "%MODEL_NAME%_blueprint.rb"), |
| 112 | + File.join(root_directory, FACTORY_GIRL_TEST_DIR, "%MODEL_NAME%_factory.rb"), # (old style) |
| 113 | + File.join(root_directory, FACTORY_GIRL_SPEC_DIR, "%MODEL_NAME%_factory.rb"), # (old style) |
| 114 | + File.join(root_directory, FACTORY_GIRL_TEST_DIR, "%TABLE_NAME%.rb"), # (new style) |
| 115 | + File.join(root_directory, FACTORY_GIRL_SPEC_DIR, "%TABLE_NAME%.rb"), # (new style) |
| 116 | + File.join(root_directory, FABRICATORS_TEST_DIR, "%MODEL_NAME%_fabricator.rb"), |
| 117 | + File.join(root_directory, FABRICATORS_SPEC_DIR, "%MODEL_NAME%_fabricator.rb") |
| 118 | + ] |
| 119 | + end |
| 120 | + |
| 121 | + def serialize_files(root_directory) |
| 122 | + [ |
| 123 | + File.join(root_directory, SERIALIZERS_DIR, "%MODEL_NAME%_serializer.rb"), |
| 124 | + File.join(root_directory, SERIALIZERS_TEST_DIR, "%MODEL_NAME%_serializer_spec.rb"), |
| 125 | + File.join(root_directory, SERIALIZERS_SPEC_DIR, "%MODEL_NAME%_serializer_spec.rb") |
| 126 | + ] |
| 127 | + end |
| 128 | + |
| 129 | + def files_by_pattern(root_directory, pattern_type) |
| 130 | + case pattern_type |
| 131 | + when 'test' then test_files(root_directory) |
| 132 | + when 'fixture' then fixture_files(root_directory) |
| 133 | + when 'scaffold' then scaffold_files(root_directory) |
| 134 | + when 'factory' then factory_files(root_directory) |
| 135 | + when 'serializer' then serialize_files(root_directory) |
| 136 | + when 'controller' |
| 137 | + [File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")] |
| 138 | + when 'admin' |
| 139 | + [File.join(root_directory, ACTIVEADMIN_DIR, "%MODEL_NAME%.rb")] |
| 140 | + when 'helper' |
| 141 | + [File.join(root_directory, HELPER_DIR, "%PLURALIZED_MODEL_NAME%_helper.rb")] |
| 142 | + else |
| 143 | + [] |
| 144 | + end |
| 145 | + end |
| 146 | + |
81 | 147 | def get_patterns(pattern_types=[])
|
82 | 148 | current_patterns = []
|
83 | 149 | root_dir.each do |root_directory|
|
@@ -233,7 +299,7 @@ def get_index_info(klass, options={})
|
233 | 299 | index_info << sprintf("# %-#{max_size}.#{max_size}s %s %s", index.name, "(#{index.columns.join(",")})", index.unique ? "UNIQUE" : "").rstrip + "\n"
|
234 | 300 | end
|
235 | 301 | end
|
236 |
| - |
| 302 | + |
237 | 303 | index_info
|
238 | 304 | end
|
239 | 305 |
|
|
0 commit comments