structuredmerge Logo by GitHub

โ˜ฏ๏ธ Yaml::Merge

Version Ruby Users Forum GitHub tag (latest SemVer) License: AGPL-3.0-only OR PolyForm-Small-Business-1.0.0 Total downloads CI Current

if ci_badges.map(&:color).detect { it != "green"} โ˜๏ธ let me know on Discord or RubyForum, as I may have missed the 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.

Sponsor Me on Github Liberapay Goal Progress Donate on PayPal Buy me a coffee Donate at ko-fi.com

๐Ÿ‘ฃ How will this project approach the September 2025 hostile takeover of RubyGems? ๐Ÿš‘๏ธ

I've summarized my thoughts in this blog post.

๐ŸŒป Synopsis Galtzo FLOSS Logo by Aboling0, CC BY-SA 4.0 ruby-lang Logo, Yukihiro Matsumoto, Ruby Visual Identity Team, CC BY-SA 2.5

Yaml::Merge is the canonical YAML family package. It is the YAML substrate for StructuredMerge Ruby: it registers the tree-sitter YAML path and should own the shared YAML merge behavior used by all YAML backends, including psych-merge. YAML parsing and backend selection enter through tree_haver; source-preserving partial document insertion, replacement, and removal should enter through ast-crispr; merge orchestration should use ast-merge.

Direct parser calls in YAML merge behavior are a smell. Tree-sitter YAML details belong behind the TreeHaver backend path, and Psych details belong behind the Psych TreeHaver backend. YAML-family code should operate on normalized owners, ranges, comments, and edit plans rather than native Ruby Hash/Array round-trips.

Key Features

  • YAML mapping-root validation.
  • Backend feature profiles for the shared language-pack parser.
  • Path-based owner matching for mapping entries.
  • Shared YAML-family merge semantics for provider gems such as psych-merge.
  • Destination-wins array policy.
  • Hash result API for fixture runners and higher-level tools.

๐Ÿ’ก Info you can shake a stick at

Tokens to Remember Gem name Gem namespace
Works with MRI Ruby 4 Ruby current Compat
Support & Community Join Me on Daily.dev's RubyFriends Get help from RubyForum Live Chat on Discord Get help from me on Upwork Get help from me on Codementor
Source Source on GitLab.com Source on CodeBerg.org Source on GitHub.com The best SHA: dQw4w9WgXcQ!
Documentation Current release on RubyDoc.info YARD on Galtzo.com Maintainer Blog GitLab Wiki GitHub Wiki
Compliance License: AGPL-3.0-only OR PolyForm-Small-Business-1.0.0 Apache license compatibility: Category X ๐Ÿ“„ilo-declaration-img Security Policy Contributor Covenant 2.1 SemVer 2.0.0
Style Enforced Code Style Linter Keep-A-Changelog 1.0.0 Gitmoji Commits Compatibility appraised by: appraisal2
Maintainer ๐ŸŽ–๏ธ Follow Me on LinkedIn Follow Me on Ruby.Social Follow Me on Bluesky Contact Maintainer My technical writing
... ๐Ÿ’– Find Me on WellFound: Find Me on CrunchBase My LinkTree More About Me ๐ŸงŠ ๐Ÿ™ ๐Ÿ›– ๐Ÿงช

Compatibility

Compatible with MRI Ruby 4.0.0+, and concordant releases of JRuby, and TruffleRuby. CI workflows and Appraisals are generated for MRI Ruby 4.0.0+. This test floor is configured by ruby.test_minimum in .kettle-jem.yml and may be higher than the gem's runtime compatibility floor when legacy Rubies are not practical for the current toolchain.

kettle-dev Logo by Aboling0, CC BY-SA 4.0

The amazing test matrix is powered by the kettle-dev stack.

How kettle-dev manages complexity in tests
Gem Source Role Total downloads
appraisal2 GitHub multi-dependency Appraisal matrix generation Total downloads for appraisal2
appraisal2-rubocop GitHub RuboCop Appraisal generator integration Total downloads for appraisal2-rubocop
kettle-dev GitHub development, release, and CI workflow tooling Total downloads for kettle-dev
kettle-jem GitHub Appraisals & CI workflow templates Total downloads for kettle-jem
kettle-soup-cover GitHub SimpleCov coverage policy and reporting Total downloads for kettle-soup-cover
kettle-test GitHub standard test runner and coverage harness Total downloads for kettle-test
rubocop-lts GitHub Ruby-version-aware linting Total downloads for rubocop-lts
turbo_tests2 GitHub parallel test execution Total downloads for turbotests2

โœจ Installation

Install the gem and add to the application's Gemfile by executing:

bundle add yaml-merge

If bundler is not being used to manage dependencies, install the gem by executing:

gem install yaml-merge

โš™๏ธ Configuration

Yaml::Merge exposes module-level functions rather than a mutable global configuration object.

profile = Yaml::Merge.yaml_backend_feature_profile
context = Yaml::Merge.yaml_plan_context

Pass backend: when calling parse_yaml, merge_yaml, or the profile helpers if you need to assert a specific backend. Unsupported backends return structured diagnostics instead of silently falling back.

๐Ÿ”ง Basic Usage

require "yaml/merge"

result = Yaml::Merge.merge_yaml(
  File.read("template.yml"),
  File.read("config.yml"),
  "yaml",
)

abort result.fetch(:diagnostics).inspect unless result.fetch(:ok)
File.write("config.yml", result.fetch(:output))

Most module-level merge methods return a Hash with :ok, :diagnostics, :output, and :policies. Check :ok before writing the result; diagnostics are structured for CI output and fixture conformance reports.

๐Ÿ” Security

See SECURITY.md.

๐Ÿค Contributing

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 issues or PRs, or use the gem and think about how it could be better.

We Keep A Changelog so if you make changes, remember to update it.

See CONTRIBUTING.md for more detailed instructions.

Code Coverage

Coverage service badges

๐Ÿ“Œ Versioning

This library follows Semantic Versioning 2.0.0 for its public API where practical. For most applications, prefer the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency("yaml-merge", "~> 7.0")
๐Ÿ“Œ Is "Platform Support" part of the public API? More details inside.

Dropping support for a platform can be a breaking change for affected users. If a release changes supported platforms, it should be called out clearly in the changelog and versioned with that impact in mind.

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.

๐Ÿ“„ License

The gem is available under the following licenses: AGPL-3.0-only, PolyForm-Small-Business-1.0.0. See LICENSE.md for details.

If none of the available licenses suit your use case, please contact us to discuss a custom commercial license.