From ac8e5e4d762cbd9df7a6b48d2542868608a9b2d6 Mon Sep 17 00:00:00 2001 From: Gabriel Dehan Date: Sat, 16 Aug 2025 04:28:00 +0200 Subject: [PATCH] feat: Add comprehensive Ruby/Rails support to ASTChunk - Add tree-sitter-ruby dependency to pyproject.toml and requirements.txt - Extend ASTChunkBuilder to support Ruby language parsing with tree-sitter-ruby - Update ASTChunk to recognize Ruby-specific node types: * class (Ruby class definitions) * module (Ruby module definitions) * method (Ruby instance methods) * singleton_method (Ruby singleton methods) * singleton_class (Ruby singleton classes) - Create comprehensive Ruby calculator example with: * Modules and nested modules * Classes with inheritance * Instance, class, and singleton methods * Rails-style concerns and patterns * Ruby metaprogramming constructs - Update README.md to include Ruby in supported languages table - Add Ruby usage examples and documentation - Create comprehensive test suite (tests/test_ruby_support.py) with 15+ test cases: * Basic Ruby class and module chunking * Rails-style controllers and models * Ruby singleton methods and metaprogramming * Complex inheritance patterns * Error handling and edge cases - Add Ruby demonstration script (examples/ruby_demo.py) - Verify no regressions in existing language support (Python, Java, C#, TypeScript) - Maintain full backward compatibility and consistent metadata structure Ruby support is now production-ready with comprehensive test coverage. ASTChunk now supports 5 languages: Python, Java, C#, TypeScript, and Ruby. --- README.md | 12 +- data/code_samples/calculator.rb | 372 ++++++++++++ .../ast_chunking_with_expansion_results.txt | 92 +-- examples/ruby_demo.py | 150 +++++ pyproject.toml | 3 +- requirements.txt | 1 + src/astchunk/astchunk.py | 19 +- src/astchunk/astchunk_builder.py | 5 +- tests/test_ruby_support.py | 568 ++++++++++++++++++ 9 files changed, 1176 insertions(+), 46 deletions(-) create mode 100644 data/code_samples/calculator.rb create mode 100644 examples/ruby_demo.py create mode 100644 tests/test_ruby_support.py diff --git a/README.md b/README.md index b2007f3..2e6cdbe 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ ASTChunk depends on [tree-sitter](https://tree-sitter.github.io/tree-sitter/) fo ```bash # Core dependencies (automatically installed) pip install numpy pyrsistent tree-sitter -pip install tree-sitter-python tree-sitter-java tree-sitter-c-sharp tree-sitter-typescript +pip install tree-sitter-python tree-sitter-java tree-sitter-c-sharp tree-sitter-typescript tree-sitter-ruby ``` ## Configuration Options @@ -96,7 +96,7 @@ class Calculator: # Initialize the chunk builder configs = { "max_chunk_size": 100, # Maximum non-whitespace characters per chunk - "language": "python", # Supported: python, java, csharp, typescript + "language": "python", # Supported: python, java, csharp, typescript, ruby "metadata_template": "default" # Metadata format for output } chunk_builder = ASTChunkBuilder(**configs) @@ -207,6 +207,13 @@ ts_builder = ASTChunkBuilder( language="typescript", metadata_template="default" ) + +# Ruby code +ruby_builder = ASTChunkBuilder( + max_chunk_size=1500, + language="ruby", + metadata_template="default" +) ```