サンプル
mustermann 4.0.0: Handle Mustermann capture type casting across built-in AST converters, POSIX character classes, polymorphic converter unions, and expand roundtripping
検証済みサンプル — gem mustermann 4.0.0: Handle Mustermann capture type casting across built-in AST converters, POSIX character classes, polymorphic converter unions…
sha256:876d66cea0502af8f4f6e05ed74179faedec2c610e764f8afdc67e86ad937985
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 1
宣言された環境
ruby linux x64 ruby ruby rubygems
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| ruby 3 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · rubygems@1 |
2026-08-16 |
| ruby 3 · linux debian/x64 · docker ed25519:2175b912ea1c23b1 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · rubygems@1 |
2026-08-18 |
ケース
HOW- ゴール
- Handle Mustermann capture type casting across built-in AST converters, POSIX character classes, polymorphic converter unions, and expand roundtripping
- パッケージ
- シンボル
-
- Mustermann.new
- Mustermann::Pattern#params
- Mustermann::Pattern#expand
- Mustermann::AST::CONVERTERS
- 環境
- ruby
- 作成日
- 2026-08-16T15:55:35Z
コントラクト
- Mustermann capture options only accept built-in converter types (Date, Gem::Version, Float, Integer, Symbol), raising Mustermann::CompileError on arbitrary classes like Time while typecasting extracted parameters into Ruby class instances and round-tripping them through expand.
- Passing an array of capture types such as [Integer, Date, :slug] creates a polymorphic capture that matches and dynamically casts each segment to its matching Ruby type or string.
- Symbol constraints that are not built-in converter names (such as :alpha or :alnum) compile to POSIX character classes and return uncasted String parameters.
- Typed parameter hashes containing Date, Gem::Version, Float, Symbol, and Integer instances serialize back into canonical URL paths via expand without requiring string conversion.
ファイル
- Gemfile
- NOTES.md
- csx.json
- test/contract.rb
ソース
source "https://rubygems.org"
gem "mustermann", "4.0.0"
gem "minitest", "5.27.0"
# Notes
### What `search_known_solution` answered
`search_known_solution` returned existing samples covering `Mustermann::Match` 0-indexing (`sha256:0664dc967dea92790848687bf9a0cd0df4c4256198916a238c609e258e44b68c`, `sha256:271fd7c6b7b13fbbab0026ad36c285a728daaf6815eb6f8c38f73cb411617c52`) and `expand` mode options with splat array handling (`sha256:0e8601385466c7cb8202d018a4f507e1647f9fae76799eec75b6ba880b0ed328`).
### What a model would have written instead
A model expects `capture:` options to accept arbitrary Ruby classes (such as `Time`) by invoking `.new` or `.parse`, expects all capture groups to return unparsed `String` instances unless manually converted, and expects symbols not mapped to converters to cause runtime errors rather than compiling to POSIX character classes.
### How the wrong version fails
Loudly raises `Mustermann::CompileError` when configuring unregistered Ruby classes in `capture:` constraints, and silently introduces type mismatch errors downstream when expecting `params` values to remain plain `String` instances instead of parsed `Date`, `Gem::Version`, `Float`, `Integer`, or `Symbol` objects.
{"case":{"believed":"Mustermann capture options accept arbitrary Ruby classes and parse them on match, while all other capture groups return raw String parameters.","caseId":"case:sha256:3b4a96eb330dbd691f528ce400baa9193c60a98e5926ec18636635ed5832ea0b","contract":["Mustermann capture options only accept built-in converter types (Date, Gem::Version, Float, Integer, Symbol), raising Mustermann::CompileError on arbitrary classes like Time while typecasting extracted parameters into Ruby class instances and round-tripping them through expand.","Passing an array of capture types such as [Integer, Date, :slug] creates a polymorphic capture that matches and dynamically casts each segment to its matching Ruby type or string.","Symbol constraints that are not built-in converter names (such as :alpha or :alnum) compile to POSIX character classes and return uncasted String parameters.","Typed parameter hashes containing Date, Gem::Version, Float, Symbol, and Integer instances serialize back into canonical URL paths via expand without requiring string conversion."],"goal":"Handle Mustermann capture type casting across built-in AST converters, POSIX character classes, polymorphic converter unions, and expand roundtripping","kind":"HOW","packages":["pkg:gem/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann.new","Mustermann::Pattern#params","Mustermann::Pattern#expand","Mustermann::AST::CONVERTERS"]},"contractCommand":["ruby","test/contract.rb"],"environment":{"arch":"x64","ecosystem":"gem","executionContext":"ruby","language":"ruby","os":"linux","packageManager":"rubygems","runtime":"ruby","schemaVersion":1},"license":"MIT-0","packages":["pkg:gem/mustermann@4.0.0"],"schemaVersion":1,"symbols":["Mustermann.new","Mustermann::Pattern#params","Mustermann::Pattern#expand","Mustermann::AST::CONVERTERS"],"verifierAdapter":"rubygems@1"}
# frozen_string_literal: true
require "minitest/autorun"
require "mustermann"
require "date"
class MustermannTypeBoundaryContractTest < Minitest::Test
def test_unsupported_class_raises_compile_error
# Arbitrary Ruby classes without built-in converters cannot be used in capture:
error = assert_raises(Mustermann::CompileError) do
Mustermann.new("/events/:time", capture: { time: Time })
end
assert_includes error.message, "no converter for class Time"
end
def test_builtin_type_converters_cast_params_and_roundtrip_through_expand
pattern = Mustermann.new(
"/pkg/:version/released/:date/by/:author/score/:score/uid/:uuid",
capture: {
version: Gem::Version,
date: Date,
author: Symbol,
score: Float,
uuid: :uuid
}
)
path = "/pkg/4.0.0.rc1/released/2026-08-16/by/alice/score/98.5/uid/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"
params = pattern.params(path)
refute_nil params
# Parameters are deserialized into rich Ruby types
assert_instance_of Gem::Version, params["version"]
assert_equal Gem::Version.new("4.0.0.rc1"), params["version"]
assert_instance_of Date, params["date"]
assert_equal Date.new(2026, 8, 16), params["date"]
assert_instance_of Symbol, params["author"]
assert_equal :alice, params["author"]
assert_instance_of Float, params["score"]
assert_equal 98.5, params["score"]
# :uuid validator validates hex UUID format but leaves parameter as String
assert_instance_of String, params["uuid"]
assert_equal "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", params["uuid"]
# Round trip: expanding using the typed params hash produces the exact canonical path
expanded = pattern.expand(params)
assert_equal path, expanded
end
def test_polymorphic_capture_union_dynamically_casts_matching_type
# Array of converters matches union of formats and typecasts to matching type
pattern = Mustermann.new("/resource/:id", capture: { id: [Integer, Date, :slug] })
# Integer branch
int_params = pattern.params("/resource/42")
refute_nil int_params
assert_instance_of Integer, int_params["id"]
assert_equal 42, int_params["id"]
# Date branch
date_params = pattern.params("/resource/2026-08-16")
refute_nil date_params
assert_instance_of Date, date_params["id"]
assert_equal Date.new(2026, 8, 16), date_params["id"]
# Slug branch (:slug converter matches slug regex but keeps String type)
slug_params = pattern.params("/resource/mustermann-release-guide")
refute_nil slug_params
assert_instance_of String, slug_params["id"]
assert_equal "mustermann-release-guide", slug_params["id"]
# Non-matching input fails match and returns nil
assert_nil pattern.params("/resource/INVALID_CHARS!@#")
end
def test_posix_symbols_validate_character_class_without_typecasting
# :alpha is not a converter name; it compiles to POSIX bracket class [[:alpha:]]
pattern = Mustermann.new("/code/:alpha_code/num/:num", capture: { alpha_code: :alpha, num: :integer })
params = pattern.params("/code/ABC/num/123")
refute_nil params
# :alpha validates alphabetic characters but leaves type as String
assert_instance_of String, params["alpha_code"]
assert_equal "ABC", params["alpha_code"]
# :integer is a registered converter symbol and typecasts to Integer
assert_instance_of Integer, params["num"]
assert_equal 123, params["num"]
# Digits in :alpha segment fail pattern match
assert_nil pattern.params("/code/123/num/123")
end
end