Separate condition evaluations for same attribute
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by tracing how conditional exposures are registered and stored in the exposures hash. Review the specs that access exposure keys directly, then determine how multiple definitions for the same attribute can be evaluated without breaking those expectations. Done means both :short and :full conditions select the appropriate value while existing specs remain valid.
Written by the indexing model from the issue text.
Description
Consider the following:
with_options if: { kind: :short } do
expose :name do |obj, opts|
"#{obj.first_name[0]}. #{obj.last_name}"
end
end
with_options if: { kind: :full } do
expose :name do |obj, opts|
"#{obj.first_name} #{obj.last_name}"
end
end
Based on the above, I would expect that if :kind is :short then the value of :name will be the first initial and last name, and if :kind is :full then the value will be the first and last name.
However, since these two exposures use the same attribute name, it's not possible to evaluated them both. The :name attribute only retains the conditional options that are defined last because they replace any previously defined options for the :name key in the the exposures hash.
This means that (for the code above) if :kind is :short then the :name attribute will not be exposed at all.
My first idea was to append some sort of unique identifier to each key in the exposures hash, but this produced a bunch of errors in the specs because they access the keys in the exposures hash directly to test values, and do not know beforehand what unique ID will be added.
Any thoughts?
- Dominant language
- Ruby
- Stars
- 729
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby-grape/grape-entity
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
ruby-grape/grape-entity#386 · 7 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#382 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ruby-grape/grape-entity#380 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ruby-grape/grape-entity#373 · 2 comments ·
-
Truncate Formatter Open
Difficulty 1/5 1-3 hours Newbie friendliness 45/100
ruby-grape/grape-entity#372 ·
All issues in ruby-grape/grape-entity
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
バグ
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
voxpupuli/puppet-epel#186 · 1 comment ·
-
external_created_at is no longer used for the message timestamp since the new message UI (v4.4.0) OpenBug Frontend
Difficulty 2/5 1-3 hours Newbie friendliness 78/100