-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Typelizer | ||
# 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 commentThe 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. |
||
{ | ||
<%- properties.each do |property| %> | ||
<%= property %>; | ||
<% end %> | ||
} | ||
ERB | ||
def initialize(serializer:, config:) | ||
@serializer = serializer | ||
@config = config | ||
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 commentThe 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. |
||
ERB.new(TEMPLATE, trim_mode: "-").result_with_hash(properties: properties) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. At the next line |
||
.flat_map { |type| extract_typescript_types(type.to_s) } | ||
.uniq | ||
.reject { |type| global_type?(type) } | ||
|
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.