-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(alba): Handle inline associations #7
Conversation
Introducing `InlineType` class for handling inline associations. This commit also adds `require "logger"` to avoid an error with console.
(base_classes + base_classes.flat_map(&:descendants)).uniq.sort_by(&:name) | ||
.reject { |serializer| Typelizer.reject_class.call(serializer: serializer) } | ||
(base_classes + base_classes.flat_map(&:descendants)).uniq | ||
.reject { |serializer| Typelizer.reject_class.call(serializer: serializer) || serializer.name.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.
Adding a condition to check anonymous serializer.
# InlineType is mainly used with Alba plugin to represent inline associations. | ||
# `name `method` is the same interface as `Interface` class. | ||
class InlineType | ||
TEMPLATE = <<~ERB.strip |
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.
Heredoc is used as a template. This can be a separate file, but it is short enough.
end | ||
|
||
def name | ||
properties = SerializerPlugins::Alba.new(serializer: @serializer, config: @config).properties |
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 kind of dirty hack, but it's recursive so that inline associations can be deeply nested.
@@ -54,6 +54,7 @@ def imports | |||
.filter_map { |interface| interface.name if interface.name != name } | |||
|
|||
custom_type_imports = attribute_types | |||
.reject { |type| type.is_a?(InlineType) } |
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.
At the next line InlineType
causes an error, so we need to reject it here.
@okuramasafumi thanks for your PR! I tried it and noticed that class FooSerializer
include Alba::Resource
helper Typelizer::DSL
many :bars do
typelize_from Bar
attributes :id, :name
end
end So I tried to fix it in #8, would love to hear your thoughts! |
Fix #6
Abstract
This change introduces a new class
InlineType
for handling inline associations of Alba.I'd like to know if this approach is good not not. If it's good, I'll add some tests for this case.
Details
There are two things to do:
I'll add some notes as a comment later.