Class: Packwerk::Parsers::Ruby
- Inherits:
-
Object
- Object
- Packwerk::Parsers::Ruby
- Includes:
- ParserInterface
- Defined in:
- lib/packwerk/parsers/ruby.rb
Defined Under Namespace
Classes: RaiseExceptionsParser, TolerateInvalidUtf8Builder
Instance Method Summary collapse
-
#call(io:, file_path: "<unknown>") ⇒ Object
: (io: (IO | StringIO), ?file_path: String) -> Parser::AST::Node?.
-
#initialize(parser_class: RaiseExceptionsParser) ⇒ Ruby
constructor
: (?parser_class: untyped) -> void.
Constructor Details
#initialize(parser_class: RaiseExceptionsParser) ⇒ Ruby
: (?parser_class: untyped) -> void
35 36 37 38 |
# File 'lib/packwerk/parsers/ruby.rb', line 35 def initialize(parser_class: RaiseExceptionsParser) @builder = TolerateInvalidUtf8Builder.new #: Object @parser_class = parser_class #: singleton(RaiseExceptionsParser) end |
Instance Method Details
#call(io:, file_path: "<unknown>") ⇒ Object
: (io: (IO | StringIO), ?file_path: String) -> Parser::AST::Node?
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/packwerk/parsers/ruby.rb', line 42 def call(io:, file_path: "<unknown>") buffer = Parser::Source::Buffer.new(file_path) buffer.source = io.read parser = @parser_class.new(@builder) parser.parse(buffer) rescue EncodingError => e result = ParseResult.new(file: file_path, message: e.) raise Parsers::ParseError, result rescue Parser::SyntaxError => e result = ParseResult.new(file: file_path, message: "Syntax error: #{e}") raise Parsers::ParseError, result end |