aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/notes/notes_command.rb
blob: 64b339b3cdd79f550e542218db8dc5a8f781c0c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require "rails/source_annotation_extractor"

module Rails
  module Command
    class NotesCommand < Base # :nodoc:
      class_option :annotations, aliases: "-a", desc: "Filter by specific annotations, e.g. Foobar TODO", type: :array, default: %w(OPTIMIZE FIXME TODO)

      def perform(*)
        require_application_and_environment!

        deprecation_warning
        display_annotations
      end

      private
        def display_annotations
          annotations = options[:annotations]
          tag = (annotations.length > 1)

          Rails::SourceAnnotationExtractor.enumerate annotations.join("|"), tag: tag, dirs: directories
        end

        def directories
          Rails::SourceAnnotationExtractor::Annotation.directories + source_annotation_directories
        end

        def deprecation_warning
          return if source_annotation_directories.empty?
          ActiveSupport::Deprecation.warn("`SOURCE_ANNOTATION_DIRECTORIES` is deprecated and will be removed in Rails 6.1. You can add default directories by using config.annotations.register_directories instead.")
        end

        def source_annotation_directories
          ENV["SOURCE_ANNOTATION_DIRECTORIES"].to_s.split(",")
        end
    end
  end
end