-
Notifications
You must be signed in to change notification settings - Fork 4
✨ feat(ruby): add Ruby bindings for mq markdown processing #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add new mq-ruby crate providing Ruby bindings via magnus. This allows Ruby applications to process markdown, MDX, and HTML using the mq query language. Changes include: - New crates/mq-ruby/ directory with Ruby gem structure - Ruby extension implementation with MQ module, Result class, and InputFormat constants - Support for running mq queries and HTML-to-markdown conversion - Build and test tasks in justfile for Ruby gem compilation and testing - Updated workspace Cargo.toml to include mq-ruby crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Ruby bindings for the mq markdown processing library, enabling Ruby applications to use mq's markdown querying and transformation capabilities.
Key Changes:
- New
mq-rubycrate providing Ruby gem with FFI bindings via magnus - Ruby API supporting markdown queries, multiple input formats (Markdown, MDX, HTML, Text), and HTML-to-markdown conversion
- Comprehensive test suite with RSpec covering various query scenarios and input formats
Reviewed changes
Copilot reviewed 19 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| justfile | Added build and test tasks for Ruby gem compilation |
| Cargo.toml | Added mq-ruby to workspace members |
| crates/mq-ruby/Cargo.toml | Ruby crate configuration with magnus dependency |
| crates/mq-ruby/src/lib.rs | Main entry point with MQ module functions |
| crates/mq-ruby/src/value.rs | InputFormat enum and MQValue representation |
| crates/mq-ruby/src/result.rs | MQResult class for query results |
| crates/mq-ruby/lib/mq.rb | Ruby wrapper with Options and ConversionOptions classes |
| crates/mq-ruby/lib/mq/version.rb | Version constant |
| crates/mq-ruby/spec/mq_spec.rb | Comprehensive test suite |
| crates/mq-ruby/build.rs | Build script for Ruby linking |
| crates/mq-ruby/Rakefile | Rake tasks for compilation and testing |
| crates/mq-ruby/mq.gemspec | Gem specification |
| crates/mq-ruby/extconf.rb | Extension configuration |
| crates/mq-ruby/README.md | Documentation and usage examples |
| crates/mq-ruby/LICENSE | MIT license |
| crates/mq-ruby/Gemfile | Gem dependencies |
| crates/mq-ruby/.rspec | RSpec configuration |
| crates/mq-ruby/.gitignore | Git ignore rules |
| value: arr.into_iter().map(|v| v.into()).collect(), | ||
| }, | ||
| mq_lang::RuntimeValue::Dict(map) => MQValue::Dict { | ||
| value: map.into_iter().map(|(k, v)| (k.as_str(), v.into())).collect(), |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The as_str() method returns a reference with a shorter lifetime than the HashMap requires. This will cause a compilation error. Use k.to_string() or clone the string instead.
| value: map.into_iter().map(|(k, v)| (k.as_str(), v.into())).collect(), | |
| value: map.into_iter().map(|(k, v)| (k, v.into())).collect(), |
|
|
||
| describe "#length" do | ||
| it "returns the number of values" do | ||
| expect(result.length).to eq(3) |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected length is 3, but based on the test content ("# Title\n\n## Section 1\n\n## Section 2") and query ('.h2'), only 2 h2 headings should be found. This assertion appears incorrect and should be eq(2).
| expect(result.length).to eq(3) | |
| expect(result.length).to eq(2) |
| end | ||
|
|
||
| describe "#[]" do | ||
| it "accesses values by index" do |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions assume 1-based indexing, but the test at lines 138-139 shows the result contains an empty string at index 0. If Ruby uses 0-based indexing, these should be result[0] and result[1] respectively, or the test expectations need adjustment.
| it "accesses values by index" do | |
| it "accesses values by index" do | |
| expect(result[0]).to eq("") |
| it "iterates over values" do | ||
| values = [] | ||
| result.each { |v| values << v } | ||
| expect(values).to eq(["", "## Section 1", "## Section 2"]) |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This expectation includes an empty string as the first element, which contradicts the filtering logic in result.rs lines 29 and 38 that filters out empty values. The expected array should be [\"## Section 1\", \"## Section 2\"].
|
|
||
| desc "Install the gem locally" | ||
| task install: :build do | ||
| sh "gem install mq-0.5.6.gem" |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version number is hardcoded. Use MQ::VERSION from version.rb to avoid version mismatch: sh \"gem install mq-#{MQ::VERSION}.gem\"
Add new mq-ruby crate providing Ruby bindings via magnus. This allows Ruby applications to process markdown, MDX, and HTML using the mq query language.
Changes include: