-
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
FlattenJson adapter no longer inherits Json adapter, renamed to Attributes #1117
FlattenJson adapter no longer inherits Json adapter, renamed to Attributes #1117
Conversation
👍 |
@beauby Thanks. I followed a somewhat non-linear path to get there, which is why I extracted CacheCheck along the way, but decided is was fine :) |
@@ -10,7 +10,7 @@ AMS does this through two components: **serializers** and **adapters**. | |||
Serializers describe _which_ attributes and relationships should be serialized. | |||
Adapters describe _how_ attributes and relationships should be serialized. | |||
|
|||
By default AMS will use the **Flatten Json Adapter**. But we strongly advise you to use **JsonApi Adapter** that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format). | |||
By default AMS will use the **Attributes Adapter**. But we strongly advise you to use **JsonApi Adapter** that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format). | |||
Check how to change the adapter in the sections bellow. |
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.
One thing that I don't like about calling the adapter attributes
is that it is harder to grep for, esp if we want to rename it again. But, we liked the name in the Slack channel, so until something better..
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.
yup, I'm not sure about the name as well, but have no suggestions so far
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.
AttributeSerialization
?
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.
Fields
, Properties
?? idk. ha
fcbae45
to
40a1daa
Compare
autoload :Null | ||
autoload :FragmentCache | ||
|
||
include CacheCheck |
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.
We are using autoload
and including it in the sequence, shouldn't we go with require
instead then?
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.
good point :)
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.
fixed
Nice work here @bf4, really fast! Can you check the comments and rebase it please ? 😄 |
40a1daa
to
fb92d25
Compare
cleaned up |
needs rebase |
Why not inherit from the json adapter? |
|
why? this is just so clean:
my concern is that duplicating code is prone to errors and repeated bugs |
@NullVoxPopuli asked:
Because, if anything, FlattenJson/Attributes is the super class. It's a more general case.
+ def serializable_hash(options = {})
+ { root => Adapter::Attributes.new(serializer).serializable_hash(options) } Nice eh? Aside: adapters and serializers should both have their own |
Maybe the common functionality could be pulled out in to a module then? or a class that both inherit from? I know inheritance isn't the answer for everything, but I do hate duplicate code. also, I hate combining that sort of stuff in to one line.. def serializable_hash(options = {})
adapter = Adapter::attributes.new(serializer)
serialized = adapter.serializable_hash(options)
{ root => serialized } much cleaner :-) and easier to debug. But anyway, with the upcoming I think there is a way to use |
Modules are inheritance. I'm not even sure how that would work without having two subclasses that include such a module if we want to keep the abstract methods in Adapter.
Where's the duplicate code. I'm not seeing it :) |
fb92d25
to
b592ebc
Compare
Rebased |
resource[:relationships][name] ||= { data: [] } | ||
resource[:relationships][name][:data] += serializers.map { |serializer| { type: serializer.json_api_type, id: serializer.id.to_s } } | ||
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.
Was accidentally re-introduced in a rebased PR
b592ebc
to
a144f55
Compare
needs rebase. But.. I think I am ok with these changes -- I like the separation of responsibility for attributes. Hopefully this will help cleanup #1127 as well. |
a144f55
to
c6f8d0f
Compare
👍 |
FlattenJson adapter no longer inherits Json adapter, renamed to Attributes
Hey guys, I just tried rebasing #1029 and ran into this. Can someone explain to me what benefit was provided by doing this as opposed to either: a) Leaving it as it was. After all In all three scenarios (including the changes in this PR) there is no duplicated code anywhere. Now effectively any adapter-specific options/defaults need to be explicitly parsed before passing them into the I favor composition the majority of the time, but I don't think this one is appropriate. I personally think we should instead break the As a concrete example, this is causing major problems for me rebasing #1029 and I don't like the solution nearly as much as I did before. IMO it's much less elegant. |
Totally agree
I get what you're saying, but the Json adapter is, I think, the wrong place
True. I agree there's got to be a better division of reponsibilities, but is the Json adapter the same as Attributes, but only with a root and meta data? That's certainly how the code looks now, but will it continue to be true? For the moment, it's simpler, I think, for the Json adapter to use the Attributes adapter than to worry about which adapter should inherit which. I'm also not convinced that mixing in an 'AttributesSerialization' module to both the Attributes Adapter and the Json Adapter improves on this. Here's how I'm thinking of the pieces now:
(or something like that) |
TODO