Sample
mustermann 4.0.0: Compile RFC 6570 URI templates from pattern ASTs and evaluate composite boolean pattern algebra across union, intersection, and symmetric difference operations
Verified sample for gem mustermann 4.0.0: Compile RFC 6570 URI templates from pattern ASTs and evaluate composite boolean pattern algebra across union…
sha256:190ddbb272d7e972c48daef00dc21a0253d99ce834f5f63c9e2cb7657bac9b35
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
ruby linux x64 ruby ruby bundler
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| ruby 3 · linux debian/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-17 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-18 |
Case
HOW- Goal
- Compile RFC 6570 URI templates from pattern ASTs and evaluate composite boolean pattern algebra across union, intersection, and symmetric difference operations
- Packages
- Symbols
-
- Mustermann.new
- Mustermann::Pattern#to_templates
- Mustermann::Composite
- Mustermann::Pattern#&
- Mustermann::Pattern#^
- Mustermann::Pattern#|
- Mustermann::Pattern#names
- Mustermann::Pattern#to_proc
- Mustermann::Sinatra
- Mustermann::Regular
- Environment
- ruby
- Created
- 2026-08-17T12:10:43Z
Contract
- Mustermann AST patterns compile into RFC 6570 URI template strings via to_templates, converting named captures to standard expressions, splats to reserved-character expansions, and optional segments into distinct permutation templates.
- Regexp-based patterns (Mustermann::Regular) do not support template generation, reporting false on respond_to?(:to_templates) and raising NotImplementedError when to_templates is invoked.
- Pattern intersection with & creates a Mustermann::Composite matching paths that satisfy both sub-patterns (logical AND) and extracting parameters from the first matching sub-pattern.
- Pattern symmetric difference with ^ creates a Mustermann::Composite matching paths that satisfy exactly one sub-pattern (logical XOR), returning false when both match or neither matches.
- Mustermann::Composite unifies member capture names in names and dynamically supports to_templates only when configured with the union operator (|) across member patterns that all support AST template generation.
- Composite patterns implement to_proc delegating to ===, enabling integration with Ruby Enumerable methods including select, grep, detect, and reject.
Files
- Gemfile
- Gemfile.lock
- NOTES.md
- csx.json
- lib/pattern_composer.rb
- test/contract.rb
Source
# frozen_string_literal: true
source "https://rubygems.org"
gem "mustermann", "4.0.0"
GEM
remote: https://rubygems.org/
specs:
mustermann (4.0.0)
PLATFORMS
ruby
x64-mingw-ucrt
x86_64-linux
DEPENDENCIES
mustermann (= 4.0.0)
CHECKSUMS
bundler (4.0.18) sha256=02d9a17429de1847b4e0c9f27a9ee4b20c0a74c0a641b4e77195d6019e3618ac
mustermann (4.0.0) sha256=91f67411bb208d1d93c41e6128cb3b0f8ddd9ec7c45966f1007e1c43c08040d7
BUNDLED WITH
4.0.18
# Mustermann URI Template Generation and Composite Boolean Logic
## What search_known_solution answered
`search_known_solution` returned existing verified solutions covering several facets of Mustermann:
- `sha256:106d01330645ca8607c6eba2a03c2fe697589bbc0b95d5851a31ee15b07f5126`: Pattern compiler option configuration (`ignore_unknown_options`, `space_matches_plus`, `capture:`, `except:`, `type: :identity`, `type: :rails`).
- `sha256:117b6e942fe9e37e5690f53de7efe111bb81d17d64ed24e9fcd18ae4827199c3`: Incremental prefix parameter consumption via `peek_params`, `safe_string` template formatting, and AST concatenation with `+`.
- `sha256:876d66cea0502af8f4f6e05ed74179faedec2c610e764f8afdc67e86ad937985`: AST type casting across built-in converters (Date, Gem::Version, Float, Integer, Symbol) and polymorphic capture unions.
- `sha256:a52cc147c58747a0e7df759e9f657bf423a1c13618128814839ec773ff27ad99`: `Mustermann::Expander` query parameter serialization and `additional_values` `:raise` default behavior.
- `sha256:66d61dfccdd0f8791209e5f8be9bfe85a6d40421464e04690eb19ee0c2faae7e`: `Mustermann::Set` linear vs trie route precedence and multi-threaded router dispatch.
- `sha256:b93244f63cc31a720f00109506358b78d33bfdbb43bf8e91519ac4a0d276f669`: Pattern memoization via `EqualityMap` and match cache controls.
This sample proves two complementary areas in Mustermann:
1. RFC 6570 URI template generation via `to_templates` across Sinatra and Rails pattern ASTs, along with the `NotImplementedError` boundary on non-AST regex patterns (`Mustermann::Regular`).
2. Boolean pattern algebra in `Mustermann::Composite` across intersection (`&`), symmetric difference (`^`), and union (`|`), including unified `names` aggregation, dynamic `to_templates` delegation, and `Enumerable` integration via `to_proc`.
## Exact Release Pinned
- `mustermann` `4.0.0`
## Observed Behavior
1. **RFC 6570 URI Template Compilation (`to_templates`)**:
- Calling `to_templates` on AST-based patterns (`Mustermann::Sinatra`, `Mustermann::Rails`) compiles the route AST into an array of RFC 6570 URI template strings.
- Named captures (e.g. `/:id`) convert to standard `{id}` expressions (`["/users/{id}"]`).
- Wildcard splats (e.g. `/*filepath`) convert to reserved `{+filepath}` expansions (`["/assets/{+filepath}"]`).
- Optional capture segments (e.g. `(.:ext)?` or `(/:id)`) generate separate template strings for each valid branch permutation (e.g. `["/docs/{topic}.{ext}", "/docs/{topic}"]`).
- Non-AST patterns (such as `Mustermann::Regular` initialized with a Ruby `Regexp`) return `false` on `respond_to?(:to_templates)` and raise `NotImplementedError` when `to_templates` is called.
2. **Intersection (`&`) Composite Pattern**:
- Binary intersection (`pattern_a & pattern_b`) produces a `Mustermann::Composite` with operator `:&`.
- Matching evaluates via logical AND: a path matches if and only if it satisfies both constituent patterns.
- `params(path)` returns the extracted parameter hash from the first matching sub-pattern when the composite matches, or `nil` on failure.
3. **Symmetric Difference (`^`) Composite Pattern**:
- Binary symmetric difference (`pattern_a ^ pattern_b`) produces a `Mustermann::Composite` with operator `:^`.
- Matching evaluates via logical XOR: a path matches if and only if it satisfies exactly one of the two constituent patterns.
- Paths matching both patterns simultaneously return `false` on `===` and `nil` on `params`.
4. **Composite Union Names Aggregation & Template Delegation**:
- `Mustermann::Composite#names` returns the deduplicated union of capture variable names across all member patterns.
- `Mustermann::Composite#to_templates` dynamically succeeds only when the composite operator is union (`:|`) and all constituent patterns support template generation. Non-union composites (`:&`, `:^`) and unions containing non-AST patterns report `false` for `respond_to?(:to_templates)` and raise `NotImplementedError`.
5. **Enumerable and `to_proc` Delegation**:
- `Mustermann::Pattern` and `Mustermann::Composite` implement `to_proc` delegating to `===`.
- Pattern instances can be passed directly with block-pass syntax (`&pattern`) to `Enumerable#select`, `Enumerable#grep`, `Enumerable#detect`, and `Enumerable#reject`.
{"case":{"caseId":"case:sha256:753e71025612307e6f99fe096dcf159a5dc664ce64c1fead7142bb28e9e5e314","contract":["Mustermann AST patterns compile into RFC 6570 URI template strings via to_templates, converting named captures to standard expressions, splats to reserved-character expansions, and optional segments into distinct permutation templates.","Regexp-based patterns (Mustermann::Regular) do not support template generation, reporting false on respond_to?(:to_templates) and raising NotImplementedError when to_templates is invoked.","Pattern intersection with \u0026 creates a Mustermann::Composite matching paths that satisfy both sub-patterns (logical AND) and extracting parameters from the first matching sub-pattern.","Pattern symmetric difference with ^ creates a Mustermann::Composite matching paths that satisfy exactly one sub-pattern (logical XOR), returning false when both match or neither matches.","Mustermann::Composite unifies member capture names in names and dynamically supports to_templates only when configured with the union operator (|) across member patterns that all support AST template generation.","Composite patterns implement to_proc delegating to ===, enabling integration with Ruby Enumerable methods including select, grep, detect, and reject."],"goal":"Compile RFC 6570 URI templates from pattern ASTs and evaluate composite boolean pattern algebra across union, intersection, and symmetric difference operations","kind":"HOW","packages":["pkg:gem/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann.new","Mustermann::Pattern#to_templates","Mustermann::Composite","Mustermann::Pattern#\u0026","Mustermann::Pattern#^","Mustermann::Pattern#|","Mustermann::Pattern#names","Mustermann::Pattern#to_proc","Mustermann::Sinatra","Mustermann::Regular"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"bundler","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann.new","Mustermann::Pattern#to_templates","Mustermann::Composite","Mustermann::Pattern#\u0026","Mustermann::Pattern#^","Mustermann::Pattern#|","Mustermann::Pattern#names","Mustermann::Pattern#to_proc","Mustermann::Sinatra","Mustermann::Regular"],"verifierAdapter":"rubygems@1"}
# frozen_string_literal: true
require "mustermann"
module PatternComposer
class << self
# Generates RFC 6570 URI template strings for an AST pattern
def generate_templates(pattern_str, type: :sinatra, **options)
pattern = pattern_str.is_a?(Mustermann::Pattern) ? pattern_str : Mustermann.new(pattern_str, type: type, **options)
pattern.to_templates
end
# Creates a composite pattern matching the intersection (logical AND) of two patterns
def intersect(pattern_a, pattern_b)
to_pattern(pattern_a) & to_pattern(pattern_b)
end
# Creates a composite pattern matching the symmetric difference (logical XOR) of two patterns
def symmetric_difference(pattern_a, pattern_b)
to_pattern(pattern_a) ^ to_pattern(pattern_b)
end
# Creates a composite pattern matching the union (logical OR) of two patterns
def union(pattern_a, pattern_b)
to_pattern(pattern_a) | to_pattern(pattern_b)
end
private
def to_pattern(pattern)
pattern.is_a?(Mustermann::Pattern) ? pattern : Mustermann.new(pattern)
end
end
end
# frozen_string_literal: true
require "mustermann"
require_relative "../lib/pattern_composer"
# 1. AST Pattern URI Template Generation (RFC 6570)
# Mustermann compiles pattern ASTs into RFC 6570 URI templates via to_templates,
# transforming named captures into {name}, splats into reserved {+path},
# and optional segments into distinct permutation templates.
p_named = Mustermann.new("/users/:id")
raise "Expected named capture to generate {id} template" unless p_named.to_templates == ["/users/{id}"]
p_splat = Mustermann.new("/assets/*filepath")
raise "Expected wildcard splat to generate reserved {+filepath} template" unless p_splat.to_templates == ["/assets/{+filepath}"]
p_optional = Mustermann.new("/docs/:topic(.:ext)?")
raise "Expected optional segment to generate permutation templates" unless p_optional.to_templates == ["/docs/{topic}.{ext}", "/docs/{topic}"]
p_rails = Mustermann.new("/articles(/:id)", type: :rails)
raise "Expected Rails optional segment to generate permutation templates" unless p_rails.to_templates == ["/articles/{id}", "/articles"]
# 2. Non-AST patterns (Mustermann::Regular) do not support template generation
# Regex-based patterns cannot be converted into RFC 6570 templates, returning false on respond_to?
# and raising NotImplementedError when to_templates is called.
p_regex = Mustermann.new(%r{/users/\d+}, type: :regexp)
raise "Expected regexp pattern to report false for respond_to?(:to_templates)" if p_regex.respond_to?(:to_templates)
begin
p_regex.to_templates
raise "Expected p_regex.to_templates to raise NotImplementedError"
rescue NotImplementedError => e
raise "Unexpected error message for to_templates on regexp" unless e.message.include?("template generation not supported")
end
# 3. Intersection (&) Composite Pattern
# The & operator creates a Mustermann::Composite matching paths that satisfy both patterns (logical AND),
# extracting parameter values from the first matching sub-pattern.
p_digit = Mustermann.new("/items/:id", capture: { id: :digit })
p_dir = Mustermann.new("/:dir/:id")
p_and = PatternComposer.intersect(p_digit, p_dir)
raise "Expected & to create a Mustermann::Composite" unless p_and.is_a?(Mustermann::Composite)
raise "Expected composite operator to be :&" unless p_and.operator == :&
# Matches only when both patterns match
raise "Expected /items/123 to match intersection" unless (p_and === "/items/123") == true
raise "Expected /users/123 to fail intersection due to directory mismatch" unless (p_and === "/users/123") == false
raise "Expected /items/abc to fail intersection due to capture constraint" unless (p_and === "/items/abc") == false
# Parameter extraction on intersection
raise "Expected params extraction on valid intersection match" unless p_and.params("/items/123") == { "id" => "123" }
raise "Expected nil params on failed intersection match" unless p_and.params("/items/abc").nil?
# 4. Symmetric Difference (^) Composite Pattern
# The ^ operator creates a Mustermann::Composite matching paths that satisfy exactly one pattern (logical XOR),
# rejecting paths that match both or neither.
p_user = Mustermann.new("/users/:id")
p_admin = Mustermann.new("/:role/admin")
p_xor = PatternComposer.symmetric_difference(p_user, p_admin)
raise "Expected ^ to create a Mustermann::Composite" unless p_xor.is_a?(Mustermann::Composite)
raise "Expected composite operator to be :^" unless p_xor.operator == :^
# Exactly one matches -> true
raise "Expected /users/42 to match XOR (matches p_user only)" unless (p_xor === "/users/42") == true
raise "Expected /orgs/admin to match XOR (matches p_admin only)" unless (p_xor === "/orgs/admin") == true
# Both match -> false (XOR property)
raise "Expected /users/admin to fail XOR because it matches both sub-patterns" unless (p_xor === "/users/admin") == false
# Neither matches -> false
raise "Expected /other/route to fail XOR because it matches neither sub-pattern" unless (p_xor === "/other/route") == false
# Params extraction on XOR
raise "Expected params for /users/42" unless p_xor.params("/users/42") == { "id" => "42" }
raise "Expected params for /orgs/admin" unless p_xor.params("/orgs/admin") == { "role" => "orgs" }
raise "Expected nil params for /users/admin (both matched)" unless p_xor.params("/users/admin").nil?
# 5. Composite Union Names Aggregation and Dynamic to_templates Delegation
# Mustermann::Composite aggregates unique parameter names across member patterns,
# and supports to_templates only when the operator is union (:|) and all members support it.
p_u1 = Mustermann.new("/api/v1/:resource")
p_u2 = Mustermann.new("/api/v2/:resource/:id")
c_union = Mustermann::Composite.new([p_u1, p_u2], operator: :|)
raise "Expected composite names to be unified list ['resource', 'id']" unless c_union.names == %w[resource id]
raise "Expected composite union of AST patterns to support to_templates" unless c_union.respond_to?(:to_templates)
raise "Expected composite union to generate all member templates" unless c_union.to_templates == ["/api/v1/{resource}", "/api/v2/{resource}/{id}"]
# Non-union composite (&) does not support to_templates
raise "Expected intersection composite to not respond to to_templates" if p_and.respond_to?(:to_templates)
begin
p_and.to_templates
raise "Expected p_and.to_templates to raise NotImplementedError"
rescue NotImplementedError => e
raise "Unexpected error on p_and.to_templates" unless e.message.include?("template generation not supported")
end
# Union composite containing a non-AST pattern does not support to_templates
c_mixed = Mustermann::Composite.new([p_u1, p_regex], operator: :|)
raise "Expected mixed union composite to not respond to to_templates" if c_mixed.respond_to?(:to_templates)
begin
c_mixed.to_templates
raise "Expected c_mixed.to_templates to raise NotImplementedError"
rescue NotImplementedError => e
raise "Unexpected error on c_mixed.to_templates" unless e.message.include?("template generation not supported")
end
# 6. Enumerable and to_proc Integration
# Patterns and composites implement to_proc delegating to ===, allowing seamless integration with
# Enumerable#select, Enumerable#grep, Enumerable#detect, and Enumerable#reject.
candidate_paths = [
"/users/42",
"/users/admin",
"/orgs/admin",
"/items/100",
"/api/v1/users"
]
# select with XOR
selected_xor = candidate_paths.select(&p_xor)
raise "Expected select(&p_xor) to filter paths matching exactly one sub-pattern" unless selected_xor == ["/users/42", "/orgs/admin"]
# reject with XOR
rejected_xor = candidate_paths.reject(&p_xor)
raise "Expected reject(&p_xor) to exclude non-matching and doubly-matching paths" unless rejected_xor == ["/users/admin", "/items/100", "/api/v1/users"]
# detect with composite union
detected_union = candidate_paths.detect(&c_union)
raise "Expected detect(&c_union) to find first matching API route" unless detected_union == "/api/v1/users"
# grep with composite pattern
grepped_and = candidate_paths.grep(p_and)
raise "Expected grep(p_and) to match /items/100 for candidate paths" unless grepped_and == ["/items/100"]
puts "All Mustermann template and composite contract assertions passed successfully."