Repository navigation
feat: add from as the inverse of as for attribute definitions - #43
Merged
Merged
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
from:option to attribute definitions — the inverse of the existingas:. Withfrom, the definition key becomes the output name andfromnames the source method/attribute:is exactly equivalent to:
Motivation
asreads "source → output", but when you think in terms of the resulting JSON shape it's often more natural to write "output ← source".fromsupports that direction.