-
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
Inline nested serializers #1193
Conversation
end | ||
return unless scope_name && !respond_to?(scope_name) | ||
self.class.class_eval do | ||
define_method scope_name, -> { scope } |
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.
Style fix – not required for this PR.
As usual, tests are failing because ruby < 2.0.1 cannot handle namespaced constants in |
Fixed \o/ |
👍 merging unless there are objections |
Wait, I have to update the changelog |
I'll rebase this as well, but let's wait for @bf4 and @joaomdmoura's remarks on code clarity and maybe some more tests. |
kk |
I think could be a good test, to make sure namespacing holds
|
@NullVoxPopuli This is done in here (the global |
89fe70c
to
34ba9f6
Compare
@@ -39,8 +40,8 @@ def inherited(base) | |||
# @example | |||
# has_many :comments, serializer: CommentSummarySerializer |
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 another @example
here with the fancy new block syntax? :-)
|
||
def test_nested_serializers | ||
actual = ActiveModel::SerializableResource.new(@tweet, adapter: :json).serializable_hash | ||
expected = { tweet: { id: 1, body: 'Tweet 1', date: 'Jan 15', author: { id: 1 }, shares: [{ id: 1, platform: 'facebook' }] } } |
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 this me multi-line formatted? with single line hashes, it can be hard to tell where some objects end (sometimes)
34ba9f6
to
26a56a5
Compare
26a56a5
to
fae14da
Compare
serializer_class_name = "#{klass.name}Serializer" | ||
serializer_class = serializer_class_name.safe_constantize | ||
# NOTE(beauby): Once we drop 1.9.3 support, we can lazify the map for better perfs. | ||
serializer_class = serializer_lookup_chain_for(klass).map(&:safe_constantize).find { |x| x } | ||
|
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.
This is the dough of this PR.
2db0240
to
a1aa2c0
Compare
Allows people to do stuff like:
I'd really love for people to submit tests to try and break the implementation.
ref #1190 #1157 #1113