Skip to content

Split flipside_entity options into their own macros - #4

Merged
sammyapoex merged 4 commits into
mainfrom
flippable-entity-macros
Oct 8, 2026
Merged

sammyapoex merged 4 commits into
mainfrom
flippable-entity-macros

Conversation

@sammyapoex

@sammyapoex sammyapoex commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Replaces the options of flipside_entity with one macro each:

class User < ApplicationRecord
  include Flipside::Flippable

  flipside_search_by do |str|
    where("lower(first_name) = :name OR lower(last_name) = :name OR email LIKE :str",
          name: str.downcase, str: "#{str}%")
  end
  flipside_display_as { |user| "#{user.name} (#{user.email})" }
  flipside_identified_by :uuid
end
  • flipside_search_by takes a block, run in the context of the class, or a column name to match exactly (flipside_search_by :name), as search_by: :name does.
  • flipside_display_as takes a block or the name of an instance method.
  • Each macro registers the class as an entity, so flipside_entity is only needed to register with the defaults. They can be called in any order.
  • An STI subclass that calls a macro gets a registration of its own, starting from its parent's settings, and must be listed in Flipside.flippables. One that calls none is still displayed through its parent.
  • The search_by:, display_as: and identified_by: options of flipside_entity still work but are deprecated, to be removed in 1.0. Each maps directly onto its macro with the same meaning, so there are no breaking changes.

Internals

RegisteredEntity is now the only place that interprets the Symbol or Proc settings. The macros set them on the class's registration, which is kept in an inherited class attribute, so a reloaded class starts over instead of keeping settings removed from its code.

Also fixes an order-dependent spec failure: SQLite's statement cache kept the old users columns when registered_entity_spec recreated the table.

Testing

bundle exec rspec: 87 examples, 0 failures, checked across several random seeds.

🤖 Generated with Claude Code

Sammy Henningsson and others added 2 commits October 7, 2026 22:49
Each takes over one option of flipside_entity and registers the class as
an entity on its own, so flipside_entity is only needed to register with
the defaults. flipside_search_by and flipside_display_as take a block or
a method name; for search that is a class method such as a scope. The
options of flipside_entity are deprecated.

Also clear the connection's statement cache when the RegisteredEntity
spec recreates the users table, which made it fail in some orders.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The Flippable macros now set these on the class's registration instead
of keeping their own copies, so the Symbol or Proc handling lives in one
place. A Symbol given as search_by now names a class method; the
deprecated options turn a column name into a search block.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The public documentation omits a registration macro and inaccurately describes identifier configuration as setting a table primary key.

2 open findings
What changed in this PR

Splits entity configuration into dedicated model macros while preserving deprecated options.

Changes:

  • Adds search, display, and identifier macros with STI support.
  • Centralizes entity setting interpretation.
  • Updates tests, documentation, and changelog.
File Description
app/​models/​flipside/​flippable.rb Implements the new macros and inherited registration.
lib/​flipside/​config/​registered_entity.rb Centralizes search and display behavior.
lib/​flipside/​config/​entities.rb Preserves deprecated symbol-search semantics.
spec/​flipside/​flippable_spec.rb Tests macros, STI, reloads, and deprecations.
spec/​flipside/​registered_entity_spec.rb Tests revised entity configuration behavior.
README.md Documents the new API and migration path.
CHANGELOG.md Records additions and deprecations.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Comment thread README.md Resolved
Comment thread README.md Resolved
Sammy Henningsson and others added 2 commits October 8, 2026 11:06
flipside_search_by :name now matches the name column exactly, as
search_by: :name always has, so moving to the new macro changes nothing.
This drops the helper that translated the old meaning.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Clarify the purpose of flipside_identified_by.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sammyapoex
sammyapoex merged commit 340e09f into main Oct 8, 2026
1 check passed
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