-
Notifications
You must be signed in to change notification settings - Fork 18
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
Various improvements #18
Conversation
This reverts commit 571b1de.
I have some additional work todo where I need all three branches merged. |
@bamorim You have been probably busy and that’s ok :) but do you think you can check this PR anytime soon? I’d really like to get these changes published :) If you need help maintaining the library, let me know, I’m happy to help. |
Hey @dvic. I'm a little bit sick now but I'll be taking holidays soon so I'll have time to check this. I'll put it in my calendar so I don't forget. |
Hope you get better soon! I advertised a bit for the library earlier today ;) https://twitter.com/dvic87/status/1479895011189735425?s=21 |
expanded = Macro.expand(unknown, env) | ||
|
||
case expanded do | ||
^unknown -> | ||
unknown | ||
|
||
{:__block__, block_context, calls} -> | ||
new_calls = Enum.map(calls, &transform_expression(&1, env)) | ||
{:__block__, block_context, new_calls} | ||
|
||
call -> | ||
transform_expression(call, env) | ||
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.
Ok, so this is the core of this PR, right?
You expand whatever call it is and:
- If it's form does not change it means it is not a macro, so you just keep it like that (
unknown
) - If it expands into a block you get all expressions and transform the expressions recursively
- Else it should be just one expression and then you recursively transform that again
Did I got it right?
Also, the test for the block case is the add_to_fields
macro, right?
defp base_type_for({:__aliases__, _, [:Ecto, :Enum]}, opts) do | ||
opts | ||
|> Keyword.get(:values, []) | ||
|> disjunction_typespec() | ||
end | ||
|
||
defp base_type_for({:__aliases__, _, _} = ast, _opts) do | ||
quote do | ||
unquote(ast).t() | ||
end | ||
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.
What this does?
Is it because the type generation was only working if no aliases were being used?
Do we have any testes for that to avoid regression?
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.
Ah, are this what solves the compile deps problem?
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.
Ah, okay, thanks for the explanation via Slack.
So for further reference, this is a required step because now we are calling TypedEctoSchema.TypeBuilder.add_field/5
with a escaped macro to remove the compile time dependency, therefore we don't necessarily have the resolved value and more often than not we have an alias, so this is required to make it work on that scenario while still not requiring a compile time dependency.
Thanks! That is a neat job!
# Gets the base type for a given Ecto.Type.t() | ||
@spec base_type_for(Ecto.Type.t(), field_options()) :: Macro.t() | ||
# Gets the base type for a given Ecto.Type.t() or an AST representing a referenced type | ||
@spec base_type_for(Ecto.Type.t() | {String.t(), Ecto.Type.t()} | Macro.t(), field_options()) :: |
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.
The {String.t(), Ecto.Type.t()}
is for the assoc case with custom source, right?
Do you think this type makes sense? Now that I think it is actually a Ecto.Queryable.t()
isn't it? (which is sad because it is just a term()
)
@@ -1,6 +1,6 @@ | |||
# This file is responsible for configuring your application | |||
# and its dependencies with the aid of the Mix.Config module. | |||
use Mix.Config |
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.
Do we even need a config? Maybe we can remove config completely.
All right, tested locally and it works.
|
It was 100% @dvic. <3 |
This PR contains #15, #16, and #17.
Updates:
field
call). This is an example of such a module: