-
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
Add support for resource-level JSON API links. #1246
Conversation
e03110e
to
9c5a9a3
Compare
@@ -50,6 +50,10 @@ def self.type(type) | |||
self._type = type | |||
end | |||
|
|||
def self.links(&block) | |||
self._links_block = block | |||
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.
My gut is to avoid long-lived blocks, as there may be a lot of these, and the memory would never be released
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.
Alternative? You actually need this block every time to instantiate a serializer.
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.
only if we design it this way. simple solution is just pass in links
to the adapter until we need more
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.
Sorry, I don't understand your last comment. Could you elaborate?
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.
Note also that there would be at most 1 block per serializer class.
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.
An other option would be to declare each link as a lambda, but that would make much more stored procs...
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 just don't think we need this code at all until someone needs 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.
I'm not sure I understand. Are you saying we should not support JSON API resource-level links?
40c7839
to
e1274b2
Compare
d346c1e
to
47ed229
Compare
@@ -159,6 +166,12 @@ def json_key | |||
root || object.class.model_name.to_s.underscore | |||
end | |||
|
|||
def links |
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.
can you add some documentation to this method since it's publicly available?
@beauby Any updates on resolving the conflicts on this? I think this is a great missing feature! Good job on this. |
@antondomratchev Thanks! The current issue is not so much about rebasing this, but about choosing the right way to handle links (since they are being declared pre-instantiation, but might rely on some stuff, such as |
e33eeac
to
4cd5761
Compare
4cd5761
to
20fb9bc
Compare
I think this way of doing links is pretty good. And it's consistent with all the block stuff you've been pushing. |
cf246bc
to
b838cf9
Compare
@@ -142,13 +143,24 @@ def resource_identifier_for(serializer) | |||
{ id: id.to_s, type: type } | |||
end | |||
|
|||
def attributes_for(serializer, fields) | |||
attributes = serializer.attributes.except(:id) | |||
attributes.slice!(*fields) if fields |
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.
slick
b838cf9
to
8b42f60
Compare
8b42f60
to
3804dcc
Compare
0221468
to
8ac2b9b
Compare
any objections to this? I'd like to get it merged. |
Add support for resource-level JSON API links.
# Used by JsonApi adapter to build resource links. | ||
def links | ||
self.class._links | ||
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.
adding an instance method is still kind of dangerous, no?
The syntax is as follows:
Update: new syntax.