W3cubDocs

/Ruby on Rails 7.0

class Rails::SourceAnnotationExtractor::Annotation

Parent:
Struct.new(:line, :tag, :text)

Public Class Methods

directories() Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 15
def self.directories
  @@directories ||= %w(app config db lib test)
end
extensions() Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 35
def self.extensions
  @@extensions ||= {}
end
register_directories(*dirs) Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 21
def self.register_directories(*dirs)
  directories.push(*dirs)
end

Registers additional directories to be included

Rails::SourceAnnotationExtractor::Annotation.register_directories("spec", "another")
register_extensions(*exts, &block) Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 41
def self.register_extensions(*exts, &block)
  extensions[/\.(#{exts.join("|")})$/] = block
end

Registers new Annotations File Extensions

Rails::SourceAnnotationExtractor::Annotation.register_extensions("css", "scss", "sass", "less", "js") { |tag| /\/\/\s*(#{tag}):?\s*(.*)$/ }
register_tags(*additional_tags) Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 31
def self.register_tags(*additional_tags)
  tags.push(*additional_tags)
end

Registers additional tags

Rails::SourceAnnotationExtractor::Annotation.register_tags("TESTME", "DEPRECATEME")
tags() Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 25
def self.tags
  @@tags ||= %w(OPTIMIZE FIXME TODO)
end

Public Instance Methods

to_s(options = {}) Show source
# File railties/lib/rails/source_annotation_extractor.rb, line 55
def to_s(options = {})
  s = +"[#{line.to_s.rjust(options[:indent])}] "
  s << "[#{tag}] " if options[:tag]
  s << text
end

Returns a representation of the annotation that looks like this:

[126] [TODO] This algorithm is simple and clearly correct, make it faster.

If options has a flag :tag the tag is shown as in the example above. Otherwise the string contains just line and text.

© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.