Class: Rails::SourceAnnotationExtractor::ParserExtractor

Inherits:
Struct
  • Object
show all
Defined in:
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

Instance Attribute Details

#patternObject

Returns the value of attribute pattern

Returns:

  • (Object)

    the current value of pattern



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

def pattern
  @pattern
end

Instance Method Details

#annotations(file) ⇒ Object



33
34
35
36
37
# File '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