Class: Rubyzen::Parsers::ASTParser
- Inherits:
-
Object
- Object
- Rubyzen::Parsers::ASTParser
- Defined in:
- lib/rubyzen/parsers/a_s_t_parser.rb
Overview
Singleton parser that converts Ruby source files into Rubyzen declarations using RuboCop’s AST processing. Results are cached via Cache::ParseCache.
Class Method Summary collapse
-
.instance ⇒ ASTParser
Returns the singleton instance of the parser.
Instance Method Summary collapse
-
#initialize ⇒ ASTParser
constructor
A new instance of ASTParser.
-
#parse_file(file_path) ⇒ Declarations::FileDeclaration?
Parses a Ruby source file and returns its declaration, using the cache.
Constructor Details
#initialize ⇒ ASTParser
Returns a new instance of ASTParser.
15 16 17 |
# File 'lib/rubyzen/parsers/a_s_t_parser.rb', line 15 def initialize @cache = Rubyzen::Cache::ParseCache.new end |
Class Method Details
.instance ⇒ ASTParser
Returns the singleton instance of the parser.
11 12 13 |
# File 'lib/rubyzen/parsers/a_s_t_parser.rb', line 11 def self.instance @instance ||= new end |
Instance Method Details
#parse_file(file_path) ⇒ Declarations::FileDeclaration?
Parses a Ruby source file and returns its declaration, using the cache.
23 24 25 26 27 28 29 30 |
# File 'lib/rubyzen/parsers/a_s_t_parser.rb', line 23 def parse_file(file_path) @cache.fetch_or_parse(file_path) do source = File.read(file_path) processed_source = RuboCop::AST::ProcessedSource.new(source, RUBY_VERSION.to_f, file_path) next nil unless processed_source.ast Rubyzen::Declarations::FileDeclaration.new(file_path, processed_source.ast) end end |