-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move meta
/meta_key
handling inside adapter.
#1233
Conversation
22c0bd0
to
56b5fb1
Compare
assert_equal @serializer.meta, 'the meta' | ||
assert_equal @serializer.meta_key, 'the meta key' | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those readers simply do not exist anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
56b5fb1
to
c4a137a
Compare
adapter = ActiveModel::Serializer::Adapter::Attributes.new(serializer) | ||
actual = ActiveModel::SerializableResource.new([@blog], adapter: :attributes, | ||
meta: { total: 10 }) | ||
.as_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting?
.as_json
feels so lonely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you rather have it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActiveModel::SerializableResource.new(
[@blog],
adapter: :attributes,
meta: { total: 10 }
).as_json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could live with that. Will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c4a137a
to
fab6f3f
Compare
can you rebase? |
thanks! |
Wait, I'll rebase. |
49f0c88
to
503bfe9
Compare
Rebased. |
woo! |
Move `meta`/`meta_key` handling inside adapter.
@@ -37,11 +37,11 @@ def cache_check(serializer) | |||
private | |||
|
|||
def meta | |||
serializer.meta if serializer.respond_to?(:meta) | |||
instance_options.fetch(:meta, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Did this break existing examples for supplying meta from with a CollectionSerializer? It doesn't seem like that's possible now. Should those be updated to show to override the adapter for this behavior? |
@trek Not sure I understand what you meant. Could you sketch some code to show what you have in mind? |
The pagination example here doesn't work after moving It looks like we didn't also add the documentation for centrally overriding serialization to include meta. The JSON API Adapter, for example, will include links automatically but the only way we could figure out how to get extra keys into the top level object (in this case for pagination) was creating our own adapter and overriding
There might be a better way, but we couldn't find an interface for it on master. It'd be good to document getting keys into the top level hash. |
@trek You are right. Note that, in master, you can always provide the |
The (toplevel)
meta
handling is clearly an adapter concern.