Created
November 26, 2017 02:46
-
-
Save skunkworker/31446bddb3949e5bc25553e8e287a45d to your computer and use it in GitHub Desktop.
How to extend annotate gem for more models.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add to app/initializers/annotate_models.rb | |
module AnnotateModels | |
class << self | |
# add your type | |
MATCHED_TYPES = %w(test fixture factory serializer scaffold controller helper serializable).freeze | |
# the directory they live in, can be more than 1 here | |
SERIALIZABLE_DIR = File.join('app', "serializers") | |
def files_by_pattern(root_directory, pattern_type) | |
puts pattern_type # for debugging | |
case pattern_type | |
when 'test' then test_files(root_directory) | |
when 'fixture' then fixture_files(root_directory) | |
when 'scaffold' then scaffold_files(root_directory) | |
when 'factory' then factory_files(root_directory) | |
when 'serializers' then serialize_files(root_directory) | |
when 'serializable' then serializable_files(root_directory) # add your files here so they can be matched | |
when 'controller' | |
[File.join(root_directory, CONTROLLER_DIR, "%PLURALIZED_MODEL_NAME%_controller.rb")] | |
when 'admin' | |
[File.join(root_directory, ACTIVEADMIN_DIR, "%MODEL_NAME%.rb")] | |
when 'helper' | |
[File.join(root_directory, HELPER_DIR, "%PLURALIZED_MODEL_NAME%_helper.rb")] | |
else | |
[] | |
end | |
end | |
# add where the files live so they can be included with the annotate. | |
def serializable_files(root_directory) | |
[ | |
File.join(root_directory, SERIALIZABLE_DIR, "serializable_%MODEL_NAME%.rb") | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment