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.

Defined Under Namespace

Classes: Parser

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



33
34
35
36
37
# File 'railties/lib/rails/source_annotation_extractor.rb', line 33

def annotations(file)
  contents = File.read(file, encoding: Encoding::BINARY)
  parser = Parser.new(contents, pattern: pattern).tap(&:parse)
  parser.error? ? [] : parser.comments
end