Skip to content

Comments

Decouple Store internals from CodeObject classes#1622

Draft
st0012 wants to merge 1 commit intomasterfrom
refactor-code-objects
Draft

Decouple Store internals from CodeObject classes#1622
st0012 wants to merge 1 commit intomasterfrom
refactor-code-objects

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Feb 22, 2026

Move resolution logic out of CodeObjects into Store:

  • Add Store#resolve_parent to encapsulate lazy parent loading (previously CodeObject#parent called load_class for disk I/O)
  • Add Store#resolve_mixin to encapsulate namespace-walking (previously 30 lines of scoping logic lived in Mixin#module)

Consolidate file normalization in base CodeObject#store=:

  • Remove redundant store= overrides from MethodAttr, AnyMethod, Mixin, and Constant that all did identical add_file calls
  • Fix pre-existing bug where AnyMethod called add_file twice

Replace direct hash reads with existing finder methods:

  • Use find_class_or_module, find_class_named, find_module_named instead of @store.classes_hash[] / @store.modules_hash[]

Simplify add_class_or_module signature:

  • Drop the all_hash parameter that passed Store's internal hash by reference; method now registers directly via the hash accessors

@matzbot
Copy link
Collaborator

matzbot commented Feb 22, 2026

🚀 Preview deployment available at: https://2e3e1cc7.rdoc-6cd.pages.dev (commit: c583935)

Move resolution logic out of CodeObjects into Store:
- Add `Store#resolve_parent` to encapsulate lazy parent loading
  (previously `CodeObject#parent` called `load_class` for disk I/O)
- Add `Store#resolve_mixin` to encapsulate namespace-walking
  (previously 30 lines of scoping logic lived in `Mixin#module`)

Consolidate file normalization in base `CodeObject#store=`:
- Remove redundant `store=` overrides from `MethodAttr`, `AnyMethod`,
  `Mixin`, and `Constant` that all did identical `add_file` calls
- Fix pre-existing bug where `AnyMethod` called `add_file` twice

Replace direct hash reads with existing finder methods:
- Use `find_class_or_module`, `find_class_named`, `find_module_named`
  instead of `@store.classes_hash[]` / `@store.modules_hash[]`

Simplify `add_class_or_module` signature:
- Drop the `all_hash` parameter that passed Store's internal hash
  by reference; method now registers directly via the hash accessors
@st0012 st0012 force-pushed the refactor-code-objects branch from 294e0bd to c583935 Compare February 22, 2026 12:38
@parser.parse_method m, RDoc::Parser::Ruby::NORMAL, tk, @comment

assert_empty @store.modules_hash.keys
assert_equal %w[M], @store.classes_hash.keys
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test was wrong: if M is added as a NormalModule, it should appear in the modules hash, not classes hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants