feat(identifier): add :as option for renaming keys#590
Conversation
Signed-off-by: Oleh Chuiev <chuevov@gmail.com>
kkohrt
left a comment
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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?
Checklist: