123456789_123456789_123456789_123456789_123456789_

Class: Rails::SourceAnnotationExtractor::ParserExtractor

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Struct
Instance Chain:
self, ::Struct
Inherits: Struct
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

  • #pattern rw

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

Instance Method Summary

::Struct - Inherited

Instance Attribute Details

#pattern (rw)

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

[ GitHub ]

  
# File 'railties/lib/rails/source_annotation_extractor.rb', line 24

class ParserExtractor < Struct.new(:pattern)

Instance Method Details

#annotations(file)

See additional method definition at line 26.

[ GitHub ]

  
# File 'railties/lib/rails/source_annotation_extractor.rb', line 49

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