lib/annotate_rb/model_annotator/annotator.rb in annotaterb-4.1.1 vs lib/annotate_rb/model_annotator/annotator.rb in annotaterb-4.2.0

- old
+ new

@@ -3,68 +3,27 @@ module AnnotateRb module ModelAnnotator class Annotator class << self def do_annotations(options = {}) - annotated = [] - - model_files_to_consider = ModelFilesGetter.call(options) - - model_files_to_consider.each do |path, filename| - file = File.join(path, filename) - - if AnnotationDecider.new(file, options).annotate? - ModelFileAnnotator.call(annotated, file, options) - end - end - - if annotated.empty? - puts 'Model files unchanged.' - else - puts "Annotated (#{annotated.length}): #{annotated.join(', ')}" - end + new(options).do_annotations end def remove_annotations(options = {}) - deannotated = [] + new(options).remove_annotations + end + end - model_files_to_consider = ModelFilesGetter.call(options) + def initialize(options) + @options = options + end - model_files_to_consider.each do |path, filename| - deannotated_klass = false - file = File.join(path, filename) + def do_annotations + ProjectAnnotator.new(@options).annotate + end - begin - klass = ModelClassGetter.call(file, options) - if klass < ActiveRecord::Base && !klass.abstract_class? - model_name = klass.name.underscore - table_name = klass.table_name - - if FileAnnotationRemover.call(file, options) - deannotated_klass = true - end - - related_files = RelatedFilesListBuilder.new(file, model_name, table_name, options).build - - related_files.each do |f, _position_key| - if File.exist?(f) - FileAnnotationRemover.call(f, options) - end - end - end - - if deannotated_klass - deannotated << klass - end - rescue StandardError => e - $stderr.puts "Unable to deannotate #{File.join(file)}: #{e.message}" - $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace] - end - end - - puts "Removed annotations from: #{deannotated.join(', ')}" - end + def remove_annotations + ProjectAnnotationRemover.new(@options).remove_annotations end end end end -