Skip to content

tighten TableForExtension readability - #5

Merged
Fivell merged 2 commits into
masterfrom
refactor/table-for-extension-cleanup
Oct 20, 2026
Merged

Fivell merged 2 commits into
masterfrom
refactor/table-for-extension-cleanup

Conversation

@Fivell

@Fivell Fivell commented Oct 20, 2026

Copy link
Copy Markdown
Member

Draft — unfinished. Opened to get this out of the working tree: it was sitting there uncommitted during the 1.0.2 release, and gem build reads the working tree, so a release build would have published code that is not in the tag.

Readability pass over TableForExtension, no behaviour change intended:

  • footer_data — collapse the nil-guard and the call into one safe navigation, keeping the defined? memoization so a nil result still caches.
  • build_footer_cell_for — build the class list declaratively with compact_blank + presence instead of the reject/join/ternary chain.
  • column_key_for — early return on the ActiveAdmin 4 title_id path, safe navigation for the ActiveAdmin 3 derived key.

Green locally on both supported majors: 25 examples, 0 failures against activeadmin 3.5.1 and 4.0.0.beta23.

Before un-drafting

One intentional guard was dropped and deserves a second look: column_key_for used to check col.title_id.respond_to?(:presence) before calling it, and now calls col.title_id.presence as soon as the column responds to title_id. That is equivalent for nil and String (both answer presence under ActiveSupport), so it holds for stock ActiveAdmin — but it would break for a title_id returning some object without presence. Worth deciding whether the original guard was defensive-by-accident or guarding a real case.

Unfinished — parked here so it stops riding along in the working tree
during releases (a `gem build` from a dirty tree would publish code that
is not in the tag).

No behaviour change intended, only expression:

* `footer_data` collapses the nil-guard and the call into one safe
  navigation, keeping the `defined?` memoization that caches a nil
  result.
* `build_footer_cell_for` builds the class list declaratively with
  `compact_blank` + `presence` instead of a reject/join/ternary chain.
* `column_key_for` returns early on the AA 4 `title_id` path and derives
  the AA 3 key with safe navigation.

Green on both supported majors locally: 25 examples, 0 failures against
activeadmin 3.5.1 and 4.0.0.beta23.
@Fivell Fivell changed the title wip: tighten TableForExtension readability tighten TableForExtension readability Oct 20, 2026
@Fivell
Fivell marked this pull request as ready for review October 20, 2026 07:33
@Fivell
Fivell requested a balanced review from Copilot October 20, 2026 07:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A false footer-data callback now raises instead of returning and caching nil.

1 open issue
What changed in this PR

A readability refactor of TableForExtension, intended to preserve behavior across ActiveAdmin 3 and 4.

Changes:

  • Simplifies footer-data callback invocation.
  • Builds footer CSS classes declaratively.
  • Streamlines column-key derivation.
File Description
lib/​activeadmin_table_footer/​table_for_extension.rb Simplifies callback handling, footer classes, and column keys.

Review effort: Balanced

Comment thread lib/activeadmin_table_footer/table_for_extension.rb Outdated
The readability pass replaced the `unless @footer_data_proc` early return
with `&.`, which only skips nil. `table_for items, footer_data: false`
therefore raised NoMethodError instead of rendering no footer.

`false` reaches @footer_data_proc through a direct `table_for` call (the
dashboard case the array specs cover) when the callback is written as
`footer_data: flag && ->(c) { ... }`. The index wrapper already treats a
falsy callback as "no footer" (`footer_proc && page_presenter.block`), so
raising here was inconsistent as well as a regression.

Guard on truthiness again, keeping the one-expression shape and the
`defined?` memoization that caches a nil result.

Two unit examples cover it; the `false` one fails on the previous commit
with "undefined method 'call' for false". 27 examples, 0 failures on
activeadmin 3.5.1 and 4.0.0.beta23.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No blocking issues were identified for supported ActiveAdmin behavior; tests were inspected but not executed.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Fivell
Fivell merged commit e184988 into master Oct 20, 2026
6 checks passed
@Fivell
Fivell deleted the refactor/table-for-extension-cleanup branch October 20, 2026 08:20
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