From 1edc7263c897f92b019d469b2861eb92419308da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Annie-Claude=20C=C3=B4t=C3=A9?= Date: Tue, 26 Jun 2018 17:18:29 -0400 Subject: [ci skip] Update documentation related to `rails notes` * Get rid of references to rake notes in the documentation * Get rid of references to environement variables used in SourceAnnotationExtractor * Updates the command line guide to reflect the new rails notes API --- railties/lib/rails/source_annotation_extractor.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 7257aaeaae..884469e20e 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -8,12 +8,7 @@ SourceAnnotationExtractor = ActiveSupport::Deprecation::DeprecatedConstantProxy. new("SourceAnnotationExtractor", "Rails::SourceAnnotationExtractor") module Rails - # Implements the logic behind the rake tasks for annotations like - # - # rails notes - # rails notes:optimize - # - # and friends. See rails -T notes and railties/lib/rails/tasks/annotations.rake. + # Implements the logic behind Rails::Command::NotesCommand. See rails notes --help for usage information. # # Annotation objects are triplets :line, :tag, :text that # represent the line where the annotation lives, its tag, and its text. Note @@ -64,10 +59,7 @@ module Rails # Prints all annotations with tag +tag+ under the root directories +app+, # +config+, +db+, +lib+, and +test+ (recursively). # - # Additional directories may be added using a comma-delimited list set using - # ENV['SOURCE_ANNOTATION_DIRECTORIES']. - # - # Directories may also be explicitly set using the :dirs key in +options+. + # Specific directories can be explicitly set using the :dirs key in +options+. # # Rails::SourceAnnotationExtractor.enumerate 'TODO|FIXME', dirs: %w(app lib), tag: true # @@ -75,7 +67,7 @@ module Rails # # See #find_in for a list of file extensions that will be taken into account. # - # This class method is the single entry point for the rake tasks. + # This class method is the single entry point for the `rails notes` command. def self.enumerate(tag, options = {}) extractor = new(tag) dirs = options.delete(:dirs) || Annotation.directories -- cgit v1.2.3 From 1996fbe2a3e46ff5698bfa3812afb7f42cdfa899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Annie-Claude=20C=C3=B4t=C3=A9?= Date: Wed, 20 Jun 2018 15:03:54 -0400 Subject: Adds a Rails::Command for Notes * It is called with `rails notes` * It defaults to displaying [OPTIMIZE, FIXME and TODO] annotations * It accepts custom annotations by using `rails notes -a CUSTOM_ANNOTATION OTHER_ANNOTATION` * It defaults to look for annotations in [app config db lib test] as dictated by SourceAnnotationExtractor * It supports ENV["SOURCE_ANNOTATION_DIRECTORIES"] but adds a deprecation warning and recommends using register_directories instead --- railties/lib/rails/commands/notes/notes_command.rb | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 railties/lib/rails/commands/notes/notes_command.rb (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/notes/notes_command.rb b/railties/lib/rails/commands/notes/notes_command.rb new file mode 100644 index 0000000000..8895cb0707 --- /dev/null +++ b/railties/lib/rails/commands/notes/notes_command.rb @@ -0,0 +1,37 @@ +# 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(*) + 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` will be deprecated 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 -- cgit v1.2.3 From 21f7dadbffdf4532e4401f1cbfa1771a8e5750da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Annie-Claude=20C=C3=B4t=C3=A9?= Date: Fri, 22 Jun 2018 12:43:32 -0400 Subject: Adds support to register directories and extensions to NotesCommand * Require the application and environnement in the notes command in order to load the config files * Adds tests for both register_directories and register_extensions added to a config file --- railties/lib/rails/commands/notes/notes_command.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/rails/commands/notes/notes_command.rb b/railties/lib/rails/commands/notes/notes_command.rb index 8895cb0707..a0faaeff8f 100644 --- a/railties/lib/rails/commands/notes/notes_command.rb +++ b/railties/lib/rails/commands/notes/notes_command.rb @@ -8,6 +8,8 @@ module Rails 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 -- cgit v1.2.3 From edf5da4b6c14eddc1fb540d8e7eec97c23baf12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Annie-Claude=20C=C3=B4t=C3=A9?= Date: Tue, 26 Jun 2018 17:12:07 -0400 Subject: Port Annotations rake task to use Rails::NotesCommand * Invokes the notes Rails::Command and passes the rake task ENV variables as annotations options to it * Adds a deprecation warning for unsupported commands * Gets rid of reference to ENV["SOURCE_ANNOTATION_DIRECTORIES"] in SourceAnnotationExtractor since its now dealt with in the NotesCommand * Gets rid of rake desc for each rake notes task so they are not documented while using `rails -T` or `rails --help` --- railties/lib/rails/source_annotation_extractor.rb | 9 ++++++++- railties/lib/rails/tasks/annotations.rake | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/source_annotation_extractor.rb b/railties/lib/rails/source_annotation_extractor.rb index 884469e20e..2d66a4dc7d 100644 --- a/railties/lib/rails/source_annotation_extractor.rb +++ b/railties/lib/rails/source_annotation_extractor.rb @@ -20,7 +20,7 @@ module Rails class SourceAnnotationExtractor class Annotation < Struct.new(:line, :tag, :text) def self.directories - @@directories ||= %w(app config db lib test) + (ENV["SOURCE_ANNOTATION_DIRECTORIES"] || "").split(",") + @@directories ||= %w(app config db lib test) end # Registers additional directories to be included @@ -54,6 +54,13 @@ module Rails s << "[#{tag}] " if options[:tag] s << text end + + # Used in annotations.rake + #:nodoc: + def self.notes_task_deprecation_warning + ActiveSupport::Deprecation.warn("This rake task is deprecated and will be removed in Rails 6.1. \nRefer to `rails notes --help` for more information.\n") + puts "\n" + end end # Prints all annotations with tag +tag+ under the root directories +app+, diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake index 60bcdc5e1b..65af778a15 100644 --- a/railties/lib/rails/tasks/annotations.rake +++ b/railties/lib/rails/tasks/annotations.rake @@ -2,21 +2,21 @@ require "rails/source_annotation_extractor" -desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" task :notes do - Rails::SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", tag: true + Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning + Rails::Command.invoke :notes end namespace :notes do ["OPTIMIZE", "FIXME", "TODO"].each do |annotation| - # desc "Enumerate all #{annotation} annotations" task annotation.downcase.intern do - Rails::SourceAnnotationExtractor.enumerate annotation + Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning + Rails::Command.invoke :notes, ["--annotations", annotation] end end - desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM" task :custom do - Rails::SourceAnnotationExtractor.enumerate ENV["ANNOTATION"] + Rails::SourceAnnotationExtractor::Annotation.notes_task_deprecation_warning + Rails::Command.invoke :notes, ["--annotations", ENV["ANNOTATION"]] end end -- cgit v1.2.3