Skip to content

feat(identifier): add :as option for renaming keys#590

Open
OlegChuev wants to merge 1 commit into
procore-oss:mainfrom
OlegChuev:main
Open

feat(identifier): add :as option for renaming keys#590
OlegChuev wants to merge 1 commit into
procore-oss:mainfrom
OlegChuev:main

Conversation

@OlegChuev
Copy link
Copy Markdown

Checklist:

  • I have updated the necessary documentation
  • I have signed off all my commits as required by DCO
  • My build is green

Signed-off-by: Oleh Chuiev <chuevov@gmail.com>
@OlegChuev OlegChuev requested review from a team and ritikesh as code owners May 21, 2026 10:01
Copy link
Copy Markdown

@kkohrt kkohrt left a comment

Choose a reason for hiding this comment

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

I appreciate the backwards compatibility aspect of this code change, but I am a little concerned about having two arguments that provide the same functionality, with one take precedence over another. That feels like it leaves room for confusion and/or accidental bugs being introduced into a system. If there is strong community support then it might make sense to allow a more general options hash for renaming, or else a configuration option to make it explicit what attribute name should be used. So I am curious as to the motivation for this change, as :name is a pretty common attribute name, but :as is not use anywhere.

Comment on lines +84 to +104
context 'Given blueprint has ::field with an :as argument' do
let(:result) { '{"first_name":"Meg","identifier":' + obj_id + '}' }
let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id, as: :identifier
field :first_name
end
end
it('returns json with a renamed field') { should eq(result) }
end

context 'Given blueprint has ::field with both :name and :as arguments' do
let(:result) { '{"first_name":"Meg","identifier":' + obj_id + '}' }
let(:blueprint) do
Class.new(Blueprinter::Base) do
field :id, name: :identifier, as: :ignored
field :first_name
end
end
it(':name takes precedence over :as') { should eq(result) }
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

To be clear, this is providing an additional argument that has the same functionality as the :name argument, but uses the keyword :as instead of :name, right?

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