Class: PackwerkYard::Parser
- Inherits:
-
Object
- Object
- PackwerkYard::Parser
- Extended by:
- T::Sig
- Includes:
- Packwerk::FileParser
- Defined in:
- lib/packwerk_yard/parser.rb
Instance Method Summary collapse
- #call(io:, file_path: "<unknown>") ⇒ Object
-
#initialize(ruby_parser: Packwerk::Parsers::Ruby.new) ⇒ Parser
constructor
A new instance of Parser.
- #match?(path:) ⇒ Boolean
Constructor Details
#initialize(ruby_parser: Packwerk::Parsers::Ruby.new) ⇒ Parser
Returns a new instance of Parser.
18 19 20 |
# File 'lib/packwerk_yard/parser.rb', line 18 def initialize(ruby_parser: Packwerk::Parsers::Ruby.new) @ruby_parser = ruby_parser end |
Instance Method Details
#call(io:, file_path: "<unknown>") ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/packwerk_yard/parser.rb', line 23 def call(io:, file_path: "<unknown>") source_code = io.read return to_ruby_ast(nil.inspect, file_path) if source_code.nil? types = extract_from_yard_to_types(source_code) to_ruby_ast( types.map { |type| to_evaluable_type(type) }.flatten .reject { |type| to_constant(type).nil? } .inspect.delete('"'), file_path, ) end |
#match?(path:) ⇒ Boolean
38 39 40 |
# File 'lib/packwerk_yard/parser.rb', line 38 def match?(path:) path.end_with?(".rb") end |