Class: Solidarity::AstProcessor
- Inherits:
-
Object
- Object
- Solidarity::AstProcessor
- Defined in:
- lib/solidarity/ast_processor.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#inheritances ⇒ Object
readonly
Returns the value of attribute inheritances.
-
#modules ⇒ Object
readonly
Returns the value of attribute modules.
Instance Method Summary collapse
-
#initialize ⇒ AstProcessor
constructor
A new instance of AstProcessor.
- #process_file(file_path) ⇒ Object
Constructor Details
#initialize ⇒ AstProcessor
Returns a new instance of AstProcessor.
9 10 11 12 13 14 |
# File 'lib/solidarity/ast_processor.rb', line 9 def initialize @classes = [] @modules = [] @inheritances = [] # Format: [['ChildClass', 'ParentClass']] @includes = [] # Format: [['ClassOrModule', 'IncludedModule']] end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
7 8 9 |
# File 'lib/solidarity/ast_processor.rb', line 7 def classes @classes end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
7 8 9 |
# File 'lib/solidarity/ast_processor.rb', line 7 def includes @includes end |
#inheritances ⇒ Object (readonly)
Returns the value of attribute inheritances.
7 8 9 |
# File 'lib/solidarity/ast_processor.rb', line 7 def inheritances @inheritances end |
#modules ⇒ Object (readonly)
Returns the value of attribute modules.
7 8 9 |
# File 'lib/solidarity/ast_processor.rb', line 7 def modules @modules end |
Instance Method Details
#process_file(file_path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/solidarity/ast_processor.rb', line 16 def process_file(file_path) content = File.read(file_path, encoding: 'UTF-8') begin ast = Parser::CurrentRuby.parse(content) traverse_ast(ast, nil) # Pass initial context as nil rescue Parser::SyntaxError => e warn "Warning: Could not parse #{file_path} due to syntax error: #{e.message}" nil # Return nil to indicate parsing failed rescue EncodingError => e warn "Warning: Could not read #{file_path} due to encoding error: #{e.message}. Attempting to force encoding to UTF-8." begin content.force_encoding('UTF-8') ast = Parser::CurrentRuby.parse(content) traverse_ast(ast, nil) rescue Parser::SyntaxError => e warn "Warning: Could not parse #{file_path} after forcing encoding due to syntax error: #{e.message}" nil rescue EncodingError => e warn "Warning: Could not read #{file_path} after forcing encoding due to encoding error: #{e.message}" nil end end end |