Repository navigation
Add Cordis::Service base class and class plugins - #4
Merged
Merged
Conversation
Mirrors upstream service.ts, adapted to Ruby idiom:
- Cordis::Service: class DSL `provide :name` / `inject :dep` (or
`inject dep: {config}`) replaces upstream's `super(ctx, name)` and
`static inject`; #initialize provides the instance as the service,
and #init runs as the plugin load body (blocking there keeps the
service invisible to dependents — pending inject via Service.init).
- Registry: Class plugins (upstream isConstructor) — runtime keyed by
the class itself (new Runtime#key field), callback wraps
`plugin.new(ctx, config)` + `instance.init`.
- Skipped (traceable-proxy machinery is out of scope): ctx rebinding,
Service[filter] isolated events, [extend] callable services, and the
provider-side check predicate. Without proxies, per-caller config is
resolved by passing the caller ctx explicitly (see demo.rb AuditLog).
- demo.rb: new act — Service class providing itself, with
ctx.intercept carrying per-caller config through resolve_config.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round 4:
Cordis::Servicebase class, aligned with upstreampackages/core/src/service.ts(4.0.0-rc.8).What
Cordis::Service— class-style plugin that provides itself as a service:provide :name/inject :dep(orinject dep: {config}) class DSL replaces upstream'ssuper(ctx, name)andstatic inject(Ruby class ivars don't need the prototype dance).#initialize(ctx, config)callsctx.provide(name, self)— the instance is the service value.#initmaps to upstreamService.init: it runs while the fiber is still loading, so blocking inside keeps the service invisible to dependents (pending inject).isConstructor):ctx.plugin(SomeClass)— runtime keyed by the class (newRuntime#key), callback wrapsplugin.new(ctx, config)+instance.init; a callable#initreturn is collected as a disposer like any plugin return.AuditLog < Cordis::Servicewithctx.interceptcarrying per-caller config throughresolve_config(the intercept showcase deferred from round 3).Deliberately skipped (ponytail)
ctxrebinding per caller,Service[filter]isolated events,[extend]callable services). Without proxies, per-caller config is resolved by passing the caller ctx explicitly to service methods.checkpredicate (untested upstream in service.spec; add when needed).provide/injectacross subclass chains (class ivars don't inherit).Tests
spec/cordis/service_base_spec.rbmirrors upstreamtests/service.spec.ts(minus proxy cases): provide-self + init-as-load-body, missingprovidedeclaration → failed fiber, pending inject, dependency-ordered chained services, Hash inject config viaresolve_config.58 examples, 0 failures.
examples/demo.rboutput verified.🤖 Generated with Claude Code