Add Evaluator.evaluate_constant to read a single constant fact - #16
Open
dfl wants to merge 1 commit into
Open
Conversation
Constant facts (no inputs, no dependencies) previously could only be read by evaluating the whole filtered graph. `evaluate_constant` builds just the one Fact and returns its resolver, so callers can read a graph constant (e.g. a per-context tax_year or state_code) without paying for a full graph evaluation on the request path. Raises ArgumentError for an unknown name, a fact that has inputs or dependencies, or an ambiguous name across modules (disambiguate with module_filter:). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dfl
marked this pull request as ready for review
July 21, 2026 00:44
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.
What
Adds
FactGraph::Evaluator.evaluate_constant(name, graph_class:, module_filter:)— reads a single constant fact's value (a fact with no inputs and no dependencies) without building or evaluating the rest of the graph.Why
Today the only way to read a constant is
Evaluator.evaluate(input, module_filter: [...]), which instantiates and runs every fact in the filtered module(s) — building Dry::Schema validators for facts you don't care about. Downstream apps (e.g. Gyraffe) have per-context constants likestate_code,max_age,tax_yeardefined asconstant(...)in the graph, but reading them on the request path meant a full filing-context evaluation. This gives a cheap, single-source read so those values don't have to be duplicated as literals in application models.evaluate_constantbuilds only the single matchingFactand returns itsresolver. It raisesArgumentErrorwhen:module_filter:to disambiguate.Tests
New
#evaluate_constantspecs inevaluator_spec.rbcover: reading a constant, not touchingprepare_fact_objects, unknown name, non-constant (has input), and cross-module ambiguity +module_filterdisambiguation. Full suite green (62 examples) and RuboCop clean.🤖 Generated with Claude Code