Skip to content

Reduce internal code to array-only concepts - #761

Open
kbrock wants to merge 5 commits into
stefankroes:masterfrom
kbrock:attribute2
Open

Reduce internal code to array-only concepts#761
kbrock wants to merge 5 commits into
stefankroes:masterfrom
kbrock:attribute2

Conversation

@kbrock

@kbrock kbrock commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Description

Prerequisite for the serializer: internal methods now work with
ancestor_ids (array) instead of the raw column string. Only the
parse/generate boundary knows about the format.

Before

Builder methods accessed the raw column directly and parsed inline.
Each method carried format knowledge (root literal, delimiter parsing).
Array format went through the same parse/generate path as strings.

After

Internal methods delegate to ancestor_ids boundary methods.
child_ancestry_value removed from format modules (only caller was
child_ancestry, which now uses generate_ancestry(path_ids)).
Array format with ancestor_ids column skips parse/generate entirely.

What this does NOT do

  • No serializer (Rails Type) yet
  • No validator changes
  • No public API changes
  • No changes to SQL generation or scopes

Non-obvious changes for developers

  • Array format now expects ancestor_ids as the column name.
  • child_ancestry_value is gone from format modules. Custom format
    subclasses should implement generate instead.
  • @_ancestor_ids ivar cache bypassed for array format. Goes away
    when serializer lands.

Type of Change

  • Feature

Checklist

  • My code follows the style guidelines
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally

How Has This Been Tested

  • bundle exec rake test (mp1 sqlite)
  • FORMAT=materialized_path2 bundle exec rake test
  • FORMAT=materialized_path3 bundle exec rake test
  • FORMAT=array DB=pg bundle exec rake test
  • ANCESTRY_COLUMN=family_tree bundle exec rake test

@kbrock kbrock changed the title Register ancestry as a Rails attribute Type Ancestry field serializer Apr 28, 2026
@kbrock
kbrock force-pushed the attribute2 branch 2 times, most recently from d859da0 to f565e5f Compare April 29, 2026 06:26
kbrock and others added 5 commits May 1, 2026 02:41
Reduces the number of methods that know about the column format.
These now delegate to the existing ancestor_ids boundary methods
rather than parsing the raw column themselves.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
child_ancestry now calls generate_ancestry(path_ids) instead of
the format module's child_ancestry_value. That method was the only
caller, so child_ancestry_value is removed from all format modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
arrays can (and probably want to) use ancestor_ids for the column
This does not work for others
So we hard coded the column name for the formatting tests

Gives us better coverage too
the value is just passed into the builder. no reason to store it
@kbrock kbrock changed the title Ancestry field serializer Reduce internal code to array-only concepts May 3, 2026
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.

1 participant