Class: Rails::SourceAnnotationExtractor::ParserExtractor

Inherits:
Struct
  • Object
show all
Defined in:
railties/lib/rails/source_annotation_extractor.rb

Overview

Wraps a regular expression that will be tested against each of the source file’s comments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#as_json

Instance Attribute Details

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



18
19
20
# File 'railties/lib/rails/source_annotation_extractor.rb', line 18

def pattern
  @pattern
end

Instance Method Details

#annotations(file) ⇒ Object



19
20
21
22
23
24
25
26
# File 'railties/lib/rails/source_annotation_extractor.rb', line 19

def annotations(file)
  result = Prism.parse_file(file)
  return [] unless result.success?

  result.comments.filter_map do |comment|
    Annotation.new(comment.location.start_line, $1, $2) if comment.location.slice =~ pattern
  end
end