Sha256: 929bfd6caf446700bfdb1e8f27508e11be21d6e01e0f117b82ed98bf3cecfe19
Contents?: true
Size: 1.88 KB
Versions: 2
Compression:
Stored size: 1.88 KB
Contents
# frozen_string_literal: true module AnnotateRb module ModelAnnotator # Annotates a model file and its related files (controllers, factories, etc) class ModelFileAnnotator class << self def call(annotated, file, options) begin klass = ModelClassGetter.call(file, options) instructions = build_instructions(klass, file, options) instructions.each do |instruction| if FileAnnotator.call_with_instructions(instruction) annotated << instruction.file end end annotated rescue BadModelFileError => e unless options[:ignore_unknown_models] $stderr.puts "Unable to annotate #{file}: #{e.message}" $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace] end rescue StandardError => e $stderr.puts "Unable to annotate #{file}: #{e.message}" $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace] end end private def build_instructions(klass, file, options = {}) instructions = [] klass.reset_column_information annotation = AnnotationGenerator.new(klass, options).generate model_name = klass.name.underscore table_name = klass.table_name model_instruction = FileAnnotatorInstruction.new(file, annotation, :position_in_class, options) instructions << model_instruction related_files = RelatedFilesListBuilder.new(file, model_name, table_name, options).build related_file_instructions = related_files.map do |f, position_key| _instruction = FileAnnotatorInstruction.new(f, annotation, position_key, options) end instructions.concat(related_file_instructions) instructions end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
annotaterb-4.1.1 | lib/annotate_rb/model_annotator/model_file_annotator.rb |
annotaterb-4.1.0 | lib/annotate_rb/model_annotator/model_file_annotator.rb |