Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@harehare
Copy link
Owner

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

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
Copilot AI review requested due to automatic review settings December 18, 2025 15:01
Copy link
Contributor

Copilot AI left a 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-ruby crate 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(),
Copy link

Copilot AI Dec 18, 2025

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.

Suggested change
value: map.into_iter().map(|(k, v)| (k.as_str(), v.into())).collect(),
value: map.into_iter().map(|(k, v)| (k, v.into())).collect(),

Copilot uses AI. Check for mistakes.

describe "#length" do
it "returns the number of values" do
expect(result.length).to eq(3)
Copy link

Copilot AI Dec 18, 2025

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).

Suggested change
expect(result.length).to eq(3)
expect(result.length).to eq(2)

Copilot uses AI. Check for mistakes.
end

describe "#[]" do
it "accesses values by index" do
Copy link

Copilot AI Dec 18, 2025

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.

Suggested change
it "accesses values by index" do
it "accesses values by index" do
expect(result[0]).to eq("")

Copilot uses AI. Check for mistakes.
it "iterates over values" do
values = []
result.each { |v| values << v }
expect(values).to eq(["", "## Section 1", "## Section 2"])
Copy link

Copilot AI Dec 18, 2025

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\"].

Copilot uses AI. Check for mistakes.

desc "Install the gem locally"
task install: :build do
sh "gem install mq-0.5.6.gem"
Copy link

Copilot AI Dec 18, 2025

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\"

Copilot uses AI. Check for mistakes.
@harehare harehare closed this Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants