Skip to content

feat: add from as the inverse of as for attribute definitions - #43

Merged
ElMassimo merged 3 commits into
mainfrom
max/from-attribute-option
Aug 28, 2026
Merged

ElMassimo merged 3 commits into
mainfrom
max/from-attribute-option

Conversation

@ElMassimo

@ElMassimo ElMassimo commented Aug 27, 2026 •

Copy link
Copy Markdown
Owner

Description

Adds a from: option to attribute definitions — the inverse of the existing as:. With from, the definition key becomes the output name and from names the source method/attribute:

attributes(
  label: {from: :name, type: :string},
  value: {from: :id,   type: :unknown},
)

is exactly equivalent to:

attributes(
  name: {as: :label, type: :string},
  id:   {as: :value, type: :unknown},
)

Motivation

as reads "source → output", but when you think in terms of the resulting JSON shape it's often more natural to write "output ← source". from supports that direction.

ElMassimo and others added 3 commits August 27, 2026 20:52
`from` lets you write the mapping with the output name as the key and the
source method/attribute named by `from`, e.g.
`attributes label: {from: :name, type: :string}`. This is the inverse of
`as` (`attributes name: {as: :label}`) and reads more naturally when you
think in terms of the resulting JSON key.

It's normalized into `as` at the single `add_attribute` funnel point, so
every entry point (attributes, attribute, serializer_attributes, etc.)
gets it for free and the underlying mechanism and metadata are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`benchmark` is no longer a default gem as of Ruby 4.0, so `require
'benchmark'` in the benchmark helper raised a LoadError on the rails-edge
CI job, failing the "Run benchmarks" step. Declare it explicitly as a
development/test dependency (alongside benchmark-ips / benchmark-memory).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ElMassimo
ElMassimo merged commit aa0a62d into main Aug 28, 2026
1 of 5 checks passed
@ElMassimo
ElMassimo deleted the max/from-attribute-option branch August 28, 2026 12:30
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