if ci_badges.map(&:color).detect { it != "green"} ☝️ let me know, as I may have missed the discord notification.
if ci_badges.map(&:color).all? { it == "green"} 👇️ send money so I can do more of this. FLOSS maintenance is now my full-time job.
👣 How will this project approach the September 2025 hostile takeover of RubyGems? 🚑️
I've summarized my thoughts in this blog post.
A collection of Ast::Merge::MergerConfig presets, YAML-based merge recipes, signature generators, and node typing classifiers for gem templating with the *-merge gem family.
The *-merge gem family provides intelligent, AST-based merging for various file formats. At the foundation is tree_haver, which provides a unified cross-Ruby parsing API that works seamlessly across MRI, JRuby, and TruffleRuby.
| Gem | Version / CI | Language / Format |
Parser Backend(s) | Description |
|---|---|---|---|---|
| tree_haver | Multi | Supported Backends: MRI C, Rust, FFI, Java, Prism, Psych, Commonmarker, Markly, Citrus, Parslet | Foundation: Cross-Ruby adapter for parsing libraries (like Faraday for HTTP) | |
| ast-merge | Text | internal | Infrastructure: Shared base classes and merge logic for all *-merge gems |
|
| bash-merge | Bash | tree-sitter-bash (via tree_haver) | Smart merge for Bash scripts | |
| commonmarker-merge | Markdown | Commonmarker (via tree_haver) | Smart merge for Markdown (CommonMark via comrak Rust) | |
| dotenv-merge | Dotenv | internal | Smart merge for .env files |
|
| json-merge | JSON | tree-sitter-json (via tree_haver) | Smart merge for JSON files | |
| jsonc-merge | JSONC | tree-sitter-jsonc (via tree_haver) | ||
| markdown-merge | Markdown | Commonmarker / Markly (via tree_haver), Parslet | Foundation: Shared base for Markdown mergers with inner code block merging | |
| markly-merge | Markdown | Markly (via tree_haver) | Smart merge for Markdown (CommonMark via cmark-gfm C) | |
| prism-merge | Ruby | Prism (prism std lib gem) |
Smart merge for Ruby source files | |
| psych-merge | YAML | Psych (psych std lib gem) |
Smart merge for YAML files | |
| rbs-merge | RBS | tree-sitter-rbs (via tree_haver), RBS (rbs std lib gem) |
Smart merge for Ruby type signatures | |
| toml-merge | TOML | Parslet + toml, Citrus + toml-rb, tree-sitter-toml (all via tree_haver) | Smart merge for TOML files |
tree_haver supports multiple parsing backends, but not all backends work on all Ruby platforms:
| Platform 👉️ TreeHaver Backend 👇️ |
MRI | JRuby | TruffleRuby | Notes |
|---|---|---|---|---|
| MRI (ruby_tree_sitter) | ✅ | ❌ | ❌ | C extension, MRI only |
| Rust (tree_stump) | ✅ | ❌ | ❌ | Rust extension via magnus/rb-sys, MRI only |
| FFI (ffi) | ✅ | ✅ | ❌ | TruffleRuby's FFI doesn't support STRUCT_BY_VALUE |
| Java (jtreesitter) | ❌ | ✅ | ❌ | JRuby only, requires grammar JARs |
| Prism (prism) | ✅ | ✅ | ✅ | Ruby parsing, stdlib in Ruby 3.4+ |
| Psych (psych) | ✅ | ✅ | ✅ | YAML parsing, stdlib |
| Citrus (citrus) | ✅ | ✅ | ✅ | Pure Ruby PEG parser, no native dependencies |
| Parslet (parslet) | ✅ | ✅ | ✅ | Pure Ruby PEG parser, no native dependencies |
| Commonmarker (commonmarker) | ✅ | ❌ | ❓ | Rust extension for Markdown (via commonmarker-merge) |
| Markly (markly) | ✅ | ❌ | ❓ | C extension for Markdown (via markly-merge) |
Legend: ✅ = Works, ❌ = Does not work, ❓ = Untested
Why some backends don't work on certain platforms:
- JRuby: Runs on the JVM; cannot load native C/Rust extensions (
.sofiles) - TruffleRuby: Has C API emulation via Sulong/LLVM, but it doesn't expose all MRI internals that native extensions require (e.g.,
RBasic.flags,rb_gc_writebarrier) - FFI on TruffleRuby: TruffleRuby's FFI implementation doesn't support returning structs by value, which tree-sitter's C API requires
Example implementations for the gem templating use case:
| Gem | Purpose | Description |
|---|---|---|
| kettle-dev | Gem Development | Development tooling, CI automation, and release workflows |
| kettle-jem | Gem Templating | Gem template library with smart merge support |
| Tokens to Remember | |
|---|---|
| Works with MRI Ruby 3 | |
| Support & Community | |
| Source | |
| Documentation | |
| Compliance | |
| Style | |
| Maintainer 🎖️ | |
... 💖 |
Compatible with MRI Ruby 3.2.0+. Due to constraints of dependencies it will not install on JRuby or TruffleRuby.
| 🚚 Amazing test matrix was brought to you by | 🔎 appraisal2 🔎 and the color 💚 green 💚 |
|---|---|
| 👟 Check it out! | ✨ github.com/appraisal-rb/appraisal2 ✨ |
Find this repo on federated forges (Coming soon!)
| Federated DVCS Repository | Status | Issues | PRs | Wiki | CI | Discussions |
|---|---|---|---|---|---|---|
| 🧪 kettle-rb/kettle-jem on GitLab | The Truth | 💚 | 💚 | 💚 | 🐭 Tiny Matrix | ➖ |
| 🧊 kettle-rb/kettle-jem on CodeBerg | An Ethical Mirror (Donate) | 💚 | 💚 | ➖ | ⭕️ No Matrix | ➖ |
| 🐙 kettle-rb/kettle-jem on GitHub | Another Mirror | 💚 | 💚 | 💚 | 💯 Full Matrix | 💚 |
| 🎮️ Discord Server | Let's | talk | about | this | library! |
Available as part of the Tidelift Subscription.
Need enterprise-level guarantees?
The maintainers of this and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
-
💡Subscribe for support guarantees covering all your FLOSS dependencies
-
💡Tidelift is part of Sonar
-
💡Tidelift pays maintainers to maintain the software you depend on!
📊@Pointy Haired Boss: An enterprise support subscription is "never gonna let you down", and supports open source maintainers Alternatively:
Install the gem and add to the application's Gemfile by executing:
bundle add kettle-jemIf bundler is not being used to manage dependencies, install the gem by executing:
gem install kettle-jemFor Medium or High Security Installations
This gem is cryptographically signed, and has verifiable SHA-256 and SHA-512 checksums by stone_checksums. Be sure the gem you install hasn’t been tampered with by following the instructions below.
Add my public key (if you haven’t already, expires 2045-04-29) as a trusted certificate:
gem cert --add <(curl -Ls https://raw.github.com/galtzo-floss/certs/main/pboling.pem)You only need to do that once. Then proceed to install with:
gem install kettle-jem -P HighSecurityThe HighSecurity trust profile will verify signed gems, and not allow the installation of unsigned dependencies.
If you want to up your security game full-time:
bundle config set --global trust-policy MediumSecurityMediumSecurity instead of HighSecurity is necessary if not all the gems you use are signed.
NOTE: Be prepared to track down certs for signed gems and add them the same way you added mine.
Kettle::Jem provides two complementary systems for merge configuration:
- Presets (Ruby classes) — Programmatic API with factory methods for in-process use
- Recipes (YAML files) — Distributable, declarative merge configurations that any project can ship and any
*-mergeconsumer can load without additional Ruby instrumentation
Presets are Ruby classes under Kettle::Jem::Presets::* that provide factory methods for creating Ast::Merge::MergerConfig objects. Each preset bundles a signature generator, node typing configuration, and freeze token appropriate for its file type. kettle-dev uses presets internally to power its gem templating workflow.
| Preset | File Types | Merger | Signature Matching | Node Typing |
|---|---|---|---|---|
Presets::Gemfile |
Gemfile, *.gemfile |
prism-merge | gem() by name, source() singleton, eval_gemfile() by path, git_source() by name, ruby() singleton |
Gem categorization (lint/test/doc/dev) |
Presets::Appraisals |
Appraisals |
prism-merge | Extends Gemfile + appraise() by name |
Appraisal categorization (ruby_version/deps/feature/runtime) |
Presets::Gemspec |
*.gemspec |
prism-merge | spec.*= by attribute, add_dependency by gem name, Gem::Specification.new singleton |
Attribute categorization (identity/metadata/files/deps/requirements) |
Presets::Rakefile |
Rakefile, *.rake |
prism-merge | task() by name, namespace() by name, desc() singleton |
Task categorization (build/test/release/lint/doc) |
Presets::Markdown |
*.md |
markly-merge | Headings by level+text, tables by header, code blocks by language | — |
Presets::Yaml |
*.yml, *.yaml |
psych-merge | Key-based (internal to psych-merge) | — |
Presets::Json |
*.json |
json-merge | Key-based (internal to json-merge) | — |
Presets::Rbs |
*.rbs |
rbs-merge | Declaration-based (internal to rbs-merge) | — |
Presets::Dotenv |
.env* |
dotenv-merge | Variable name matching (internal to dotenv-merge) | — |
Each preset provides three factory methods:
destination_wins— Preserve destination customizations; template-only content is skippedtemplate_wins— Apply template updates; template-only content is addedcustom— Full control over preference, add_template_only, freeze_token, and node_typing
Recipes are self-contained YAML files designed to be distributable units of merge knowledge. A project can ship a recipe alongside its templates, allowing any consumer of the *-merge gem family to perform intelligent merges without writing Ruby merge logic.
A simple recipe is just a YAML file — no companion folder or Ruby scripts required:
name: my_config
description: Merge YAML config files with destination preference
parser: psych
merge:
preference: destination
add_missing: true
freeze_token: my-projectFor advanced recipes that need custom signature matching or node categorization, a companion folder can optionally contain small Ruby scripts (signature generators, node typing lambdas) that are loaded on demand. The consumer only needs ast-merge to load and use them.
| Recipe | YAML File | Parser | Description |
|---|---|---|---|
:gemfile |
recipes/gemfile.yml |
prism |
Gemfile merging with gem-name-aware signature matching and gem categorization node typing |
:gemspec |
recipes/gemspec.yml |
prism |
Gemspec merging with attribute assignment and dependency matching |
:rakefile |
recipes/rakefile.yml |
prism |
Rakefile merging with task/namespace/require matching |
:appraisals |
recipes/appraisals.yml |
prism |
Appraisals merging extending Gemfile signatures with appraise() block matching |
:markdown |
recipes/markdown.yml |
markly |
Markdown merging with heading, table, and code block matching |
Each recipe YAML defines:
name— Recipe identifierdescription— Human-readable descriptionparser— Which*-mergeparser to use (prism,markly, etc.)merge.preference— Default merge preference (:templateor:destination)merge.add_missing— Whether to add template-only nodes to the resultmerge.signature_generator— Path to companion Ruby script (relative to recipe folder)merge.node_typing— Hash mapping node class names to companion Ruby scriptsfreeze_token— Token for freeze block preservation
Any project can create and distribute recipes. A minimal recipe is a single YAML file:
my - project /
recipes /
my_format.yml
For recipes that need custom signature matching or node categorization, add a companion folder with Ruby scripts. The folder name must match the recipe name (without the .yml extension):
my - project /
recipes /
my_format.yml
my_format/ # Optional companion folder
signature_generator.rb # Returns a lambda for node matching
typing /
call_node.rb # Returns a lambda for node categorization
Then consumers load it directly:
preset = Ast::Merge::Recipe::Preset.load("path/to/my_format.yml")
merger = Prism::Merge::SmartMerger.new(template, destination, **preset.to_h)
result = merger.mergeNo dependency on kettle-jem is required — only ast-merge and the appropriate *-merge gem for parsing.
The default freeze token for kettle-jem is kettle-jem. This means freeze markers look like:
# kettle-jem:freeze
# ... content to preserve ...
# kettle-jem:unfreezeWhen using kettle-jem's merge configurations with Ruby files (gemspecs, Gemfiles, etc.), you can protect sections from being overwritten by the template using freeze markers.
# kettle-jem:freeze
gem "my-custom-gem", path: "../local-fork"
gem "another-local-gem", git: "https://github.com/my-org/gem.git"
# kettle-jem:unfreezeYou can also freeze a single Ruby statement by placing a freeze comment immediately before it:
# kettle-jem:freeze
gem "my-custom-gem", "~> 1.0"# kettle-jem:freeze
class MyCustomClass
# EVERYTHING inside this class is frozen!
# Template changes to this class will be ignored.
def custom_method
# ...
end
end
# kettle-jem:freeze
Gem::Specification.new do |spec|
# The entire gemspec block is frozen
# Use this carefully - it prevents ALL template updates!
endFrozen statements are matched by their structural identity, not their content:
- A frozen
gem "example"matchesgem "example"in the template (by gem name) - A frozen
spec.add_dependency "foo"matches the same dependency in the template - A frozen
class Foomatchesclass Fooin the template (by class name) The destination's frozen version is always preserved, regardless of changes in the template.
kettle:jem:template looks at .kettle-jem.yml to determine how each file should be updated. The config supports a hybrid format: a list of ordered glob patterns used as fallbacks and a files nested map for per-file configurations. Each entry ultimately exposes a strategy (and optional merge options for Ruby files).
| Strategy | Behavior |
|---|---|
skip |
Legacy behavior: template content is copied with token replacements and any bespoke merge logic already in place. |
replace |
Template AST replaces the destination outside of kettle-jem:freeze sections. |
append |
Only missing AST nodes (e.g., gem or task declarations) are appended; existing nodes remain untouched. |
merge |
Destination nodes are updated in-place using the template AST (used for Gemfile, *.gemspec, and Rakefile). |
All Ruby files receive this reminder (inserted after shebang/frozen-string-literal lines):
# To force retention during kettle-jem templating:
# kettle-jem:freeze
# # ... your code
# kettle-jem:unfreeze
Wrap any code you never want rewritten between kettle-jem:freeze / kettle-jem:unfreeze comments. When an AST merge fails, the task emits an error asking you to file an issue at https://github.com/kettle-rb/kettle-jem/issues and then aborts—there is no regex fallback.
- The templating step dynamically prefers any
*.examplefile present in this gem's templates. When a*.exampleexists alongside the non-example template, the.examplecontent is used, and the destination file is written without the.examplesuffix. - This applies across all templated files, including:
- Root files like
.gitlab-ci.yml(copied from.gitlab-ci.yml.examplewhen present). - Nested files like
.github/workflows/coverage.yml(copied from.github/workflows/coverage.yml.examplewhen present).
- Root files like
- This behavior is automatic for any future
*.examplefiles added to the templates. - Exception:
.env.localis handled specially for safety. Regardless of whether the template provides.env.localor.env.local.example, the installer copies it to.env.local.examplein your project, and will never create or overwrite.env.local.
Here is an example .kettle-jem.yml (hybrid format):
# Defaults applied to per-file merge options when strategy: merge
defaults:
preference: "template"
add_template_only_nodes: true
# Ordered glob patterns (first match wins)
patterns:
- path: "*.gemspec"
strategy: merge
- path: "gemfiles/modular/erb/**"
strategy: merge
- path: ".github/**/*.yml"
strategy: skip
# Per-file nested configuration (overrides patterns)
files:
"Gemfile":
strategy: merge
add_template_only_nodes: true
"Rakefile":
strategy: merge
"README.md":
strategy: replace
".env.local":
strategy: skipkettle-jem ships a single executable, kettle-jem, that bootstraps a host gem repository to use kettle-jem tooling. Run it from inside the target gem's repository working directory.
kettle-jem [options]
# e.g., kettle-jem --allowed=true --forceThe kettle-jem command performs the following steps in order:
- Prechecks — Verifies you're inside a git repo with a clean working tree, a gemspec, and a Gemfile
- Sync dev dependencies — Updates your gemspec's
add_development_dependencyentries to match the kettle-jem template - Sync Gemfile — Ensures your Gemfile contains required
source,git_source,gemspec, andeval_gemfiledirectives from the template - Sync modular gemfiles — Copies
gemfiles/modular/*.gemfilefiles from the template - Ensure bin/setup — Copies
bin/setupfrom the template if missing - Ensure Rakefile — Replaces your Rakefile with the kettle-jem template Rakefile
- Run bin/setup — Executes
bin/setupto install dependencies - Generate binstubs — Runs
bundle binstubs --all - Commit bootstrap changes — Commits any changes from the above steps
- Run kettle:jem:install — Invokes the full template merge via
rake kettle:jem:install, which performs AST-based smart merging of all template files according to.kettle-jem.yml
All options are passed through to the underlying rake kettle:jem:install task:
| Option | Description |
|---|---|
--allowed=VAL |
Acknowledge prior direnv allow, etc. Passed as allowed=VAL to the rake task. |
--force |
Accept all prompts non-interactively (sets force=true). Useful for CI or scripted setups. |
--hook_templates=VAL |
Control git hook templating. Values: local (install to .git/hooks), global (install to ~/.git-templates), skip (do not install hooks). |
--only=VAL |
Restrict install scope to a specific subset of files. |
--include=VAL |
Include optional files by glob pattern. |
-h, --help |
Show help and exit. |
| Variable | Description |
|---|---|
DEBUG=true |
Print full backtraces on errors |
FUNDING_ORG=org_name |
Override the GitHub org used for FUNDING.yml generation. Auto-derived from git remote origin when not set. Set to false to disable. |
Bootstrap a new gem repository with all defaults (interactive prompts):
cd my-gem
kettle-jemNon-interactive setup for CI:
kettle-jem --forceOnly install git hooks locally:
kettle-jem --hook_templates=localAfter initial setup, the following rake tasks are available for ongoing use:
| Task | Description |
|---|---|
rake kettle:jem:install |
Full template merge (same as what kettle-jem runs at the end) |
rake kettle:jem:template |
File templating only (AST-based smart merge of all template files) |
rake kettle:jem:selftest |
Validate that templating kettle-jem against itself produces expected output |
Presets are the programmatic Ruby API, used by kettle-dev for in-process gem templating:
require "kettle/jem"
# Merge a Gemfile with template preference
config = Kettle::Jem::Presets::Gemfile.template_wins
merger = Prism::Merge::SmartMerger.new(template_content, destination_content, **config.to_h)
result = merger.merge
# Merge a gemspec preserving destination customizations
config = Kettle::Jem::Presets::Gemspec.destination_wins(freeze_token: "my-project")
merger = Prism::Merge::SmartMerger.new(template_content, destination_content, **config.to_h)
result = merger.merge
# Merge Markdown with template priority
config = Kettle::Jem::Presets::Markdown.template_wins
merger = Markly::Merge::SmartMerger.new(template_content, destination_content, **config.to_h)
result = merger.merge
# Custom merge with per-type preferences
config = Kettle::Jem::Presets::Gemspec.custom(
preference: {
default: :destination,
spec_metadata: :template, # Update metadata from template
},
add_template_only: true,
freeze_token: "kettle-dev",
)
merger = Prism::Merge::SmartMerger.new(template_content, destination_content, **config.to_h)
result = merger.mergeRecipes provide a declarative, distributable approach to merge configuration. A project ships a recipe YAML (and companion scripts), and consumers load it without needing to write merge instrumentation in Ruby:
require "kettle/jem"
# Load a built-in recipe by name
preset = Kettle::Jem.recipe(:gemfile)
# Use it with a SmartMerger
merger = Prism::Merge::SmartMerger.new(
template_content,
destination_content,
**preset.to_h,
)
result = merger.merge
# List available built-in recipes
Kettle::Jem.available_recipes # => [:appraisals, :gemfile, :gemspec, :markdown, :rakefile]
# Load a recipe from any path (no kettle-jem dependency needed — only ast-merge)
preset = Ast::Merge::Recipe::Preset.load("/path/to/third-party/recipe.yml")
merger = Prism::Merge::SmartMerger.new(template, destination, **preset.to_h)
result = merger.mergeWhile kettle-rb tools are free software and will always be, the project would benefit immensely from some funding. Raising a monthly budget of... "dollars" would make the project more sustainable.
We welcome both individual and corporate sponsors! We also offer a wide array of funding channels to account for your preferences (although currently Open Collective is our preferred funding platform).
If you're working in a company that's making significant use of kettle-rb tools we'd appreciate it if you suggest to your company to become a kettle-rb sponsor.
You can support the development of kettle-rb tools via GitHub Sponsors, Liberapay, PayPal, Open Collective and Tidelift.
| 📍 NOTE |
|---|
| If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend the use of Tidelift, where you can get a support-like subscription instead. |
Support us with a monthly donation and help us continue our activities. [Become a backer]
NOTE: kettle-readme-backers updates this list every day, automatically.
No backers yet. Be the first!
Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]
NOTE: kettle-readme-backers updates this list every day, automatically.
No sponsors yet. Be the first!
I’m driven by a passion to foster a thriving open-source community – a space where people can tackle complex problems, no matter how small. Revitalizing libraries that have fallen into disrepair, and building new libraries focused on solving real-world challenges, are my passions. I was recently affected by layoffs, and the tech jobs market is unwelcoming. I’m reaching out here because your support would significantly aid my efforts to provide for my family, and my farm (11 🐔 chickens, 2 🐶 dogs, 3 🐰 rabbits, 8 🐈 cats).
If you work at a company that uses my work, please encourage them to support me as a corporate sponsor. My work on gems you use might show up in bundle fund.
I’m developing a new library, floss_funding, designed to empower open-source developers like myself to get paid for the work we do, in a sustainable way. Please give it a look.
Floss-Funding.dev: 👉️ No network calls. 👉️ No tracking. 👉️ No oversight. 👉️ Minimal crypto hashing. 💡 Easily disabled nags
See SECURITY.md.
If you need some ideas of where to help, you could work on adding more code coverage, or if it is already 💯 (see below) check reek, issues, or PRs, or use the gem and think about how it could be better.
We so if you make changes, remember to update it.
See CONTRIBUTING.md for more detailed instructions.
See CONTRIBUTING.md.
Everyone interacting with this project's codebases, issue trackers,
chat rooms and mailing lists agrees to follow the .
Made with contributors-img.
Also see GitLab Contributors: https://gitlab.com/kettle-rb/kettle-jem/-/graphs/main
This Library adheres to .
Violations of this scheme should be reported as bugs.
Specifically, if a minor or patch version is released that breaks backward compatibility,
a new version should be immediately released that restores compatibility.
Breaking changes to the public API will only be introduced with new major versions.
dropping support for a platform is both obviously and objectively a breaking change
—Jordan Harband (@ljharb, maintainer of SemVer) in SemVer issue 716
I understand that policy doesn't work universally ("exceptions to every rule!"), but it is the policy here. As such, in many cases it is good to specify a dependency on this library using the Pessimistic Version Constraint with two digits of precision.
For example:
spec.add_dependency("kettle-jem", "~> 1.0")📌 Is "Platform Support" part of the public API? More details inside.
SemVer should, IMO, but doesn't explicitly, say that dropping support for specific Platforms is a breaking change to an API, and for that reason the bike shedding is endless.
To get a better understanding of how SemVer is intended to work over a project's lifetime, read this article from the creator of SemVer:
See CHANGELOG.md for a list of releases.
The gem is available as open source under the terms of
the MIT License .
See LICENSE.txt for the official Copyright Notice.
-
Copyright (c) 2025 - 2026 Peter H. Boling, of
Galtzo.com
, and kettle-jem contributors.
Maintainers have teeth and need to pay their dentists. After getting laid off in an RIF in March, and encountering difficulty finding a new one, I began spending most of my time building open source tools. I'm hoping to be able to pay for my kids' health insurance this month, so if you value the work I am doing, I need your support. Please consider sponsoring me or the project.
To join the community or get help 👇️ Join the Discord.
To say "thanks!" ☝️ Join the Discord or 👇️ send money.
Thanks for RTFM.