DEV Community

Evgenii S.
Evgenii S.

Posted on • Edited on • Originally published at brownbox.dev

Grepfruit v3.2: Programmatic API for Text Search

Grepfruit, a ractor-powered text search gem, adds a programmatic API in v3.2, a count-only mode, and Ruby 4 support.

What's new?

Programmatic API

The gem can now be used programmatically directly in Ruby applications:

Grepfruit.search(
  regex: /TODO/, 
  path: "spec/test_dataset", 
  exclude: ["foo.md", "baz.py"]
)
# returns =>
{
  search: {
    pattern: /TODO/,
    directory: "/Users/enjaku/Development/grepfruit/spec/test_dataset",
    exclusions: ["foo.md", "baz.py"],
    inclusions: []
  },
  summary: {
    files_checked: 2,
    files_with_matches: 2,
    total_matches: 4
  },
  matches: [
    {file: "bar.txt", line: 3, content: "TODO: Fix the alignment issue in the header."},
    {file: "bar.txt", line: 7, content: "TODO: Update the user permissions module."},
    {file: "bar.txt", line: 14, content: "TODO: Review the new design specifications."},
    {file: "folder/bad.yml", line: 21, content: "# TODO: Add configuration for cache settings"}
  ]
}
Enter fullscreen mode Exit fullscreen mode

All CLI options are available as keyword arguments, and the API returns structured data that should be easy to work with in Ruby scripts.

Count-only mode

Use the --count flag (or count: true in the API) to show only match statistics without displaying the actual matches.

Ruby 4 support

Grepfruit now supports Ruby 4 and its updated Ractor implementation.

Check out the gem here.
Happy coding!

Top comments (0)