Repository navigation
Remove leftovers of the Compiler consolidation - #1861
Draft
neilvcarvalho wants to merge 3 commits into
Draft
neilvcarvalho wants to merge 3 commits into
neilvcarvalho wants to merge 3 commits into
Conversation
Declaration::Implicit kept a reference to the definition it was declared in. That was needed when the declaration resolved itself into an attribute. Compiler now does that work and receives the definition directly, so nothing reads the reference any more. This commit removes the reader and the constructor argument, which leaves the three declaration classes as plain records of what a factory or trait block declared. They stay as classes instead of becoming Structs because a bare word in a definition block returns the declaration to user code. A Struct would add Enumerable and index access to that value and change its to_s, which the sequence guards in Evaluator and Syntax::Methods match on to report a missing scope. There are no side effects for users. The spec example that compared implicit declarations by factory is removed with the attribute.
Factory#parent answered a NullFactory when a factory had no parent. After the Compiler consolidation that object only supplied a nil class name and the compiled global configuration, plus an empty definition that the trait and enum lookups walked for no result. Factory#parent now answers nil without a parent. Compiler asks Internal for the compiled configuration in that case, the class name lookup uses safe navigation, and the Linter fallback stops at nil. Compiler already treated a nil factory as the end of the parent chain when collecting traits and enum settings. Factory is private API, so there are no side effects for users. The NullFactory examples move to the Factory and Internal specs, where the behavior now lives.
Compiler#inherited shared its name with a local variable in traits_in_scope_of that holds the parent's traits. The local shadowed the method, so one name meant a CompiledFactory in one place and an Array of traits in another. The method is now parent_compiled. The compiled_configuration examples compared the snapshot against untouched global defaults, so they would pass even if the snapshot ignored the configuration. They now register a global callback, constructor and to_create before reading the snapshot. There are no side effects on behavior.
neilvcarvalho
marked this pull request as draft
November 27, 2026 20:15
This branch has not been deployed
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.
The Compiler consolidation (#1853) left a few classes behind that no longer do what they were built for. This pull request removes or shrinks them without changing public behavior. Each commit leaves the suite green.
Deleted
NullFactory(lib/factory_bot/null_factory.rband its spec).Factory#parentnow answersnilfor a factory without a parent.CompilerasksInternal.compiled_configurationin that case,Factory#class_nameuses safe navigation and theLinterfallback stops atnil.Compileralready treated anilfactory as the end of the parent chain for traits and enum settings. TheNullFactoryexamples moved tofactory_spec.rbandinternal_spec.rb.Declaration::Implicit#factoryand its constructor argument.Compilerreceives the definition directly, so nothing read it. The one example that compared implicit declarations by factory went with it, and thewith_factorychain of the declaration matcher.Kept, and why
Declaration,Declaration::Dynamic,Declaration::Association,Declaration::Implicit. After the change above they carry no behavior (noto_attributes, nobuild), only readers and==. They stay as classes instead of Structs for two reasons. A bare word in a definition block returns the declaration to user code, so a Struct would addEnumerable,[],sizeandto_ato that value. A Struct also changesto_s, and the guards inEvaluator#increment_sequenceandSyntax::Methods#increment_sequencematch on the"#<FactoryBot::Declaration"prefix. Those guards detect a sequence block that interpolates an attribute name when no scope was given (sequence(:info) { |n| "#{name}" }thengenerate(:user, :info)), and turn it into the "Perhaps it needs a scope to operate?" error.Compileralso usesis_a?(Declaration)to report a bare word passed asfactory:or as an association override.AttributeList, unchanged. It is theattributesvalue of thefactory_bot.compile_factorypayload, and it is already trimmed to what subscribers can observe: enumeration,names,associations,transientandnon_transient. A plain Array cannot keep those readers.Strategy::Null, unchanged and still registered as:null. It is not only a public strategy:Strategy::AttributesFor#associationruns associations withrunner.run(:null), soattributes_fordepends on it.spec/support/matchers/declaration.rband its include inspec_helper.rb, becausedefinition_proxy_spec.rbstill asserts on the declarations the proxy records.Verification
bundle exec rake all_specson the default gemfile (Ruby 4.0.10): 312 unit examples, 457 acceptance examples, 4 scenarios, 0 failures.BUNDLE_GEMFILE=gemfiles/7.0.gemfile bundle exec rake all_specs: same counts, 0 failures.BUNDLE_GEMFILE=gemfiles/main.gemfile bundle exec rake all_specs: same counts, 0 failures.bundle exec standardrb: 147 files inspected, no offenses.No file under
spec/acceptancewas edited.