-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adding conditional callbacks #495
Conversation
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.
Just missing the error for an invalid unless, otherwise it looks good and I'm glad we can remove those skips.
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.
So stoked for this!
/sparkle @matthewmcgarvey for the review |
…oved compile time errors out for a little less clutter
weird... no clue why ameba failed randomly... Probably a fluke though. |
@jwoertink it seems to be the Callbacks module. Here is the most minimal I'm able to make the file and still cause that error module Avram::Callbacks
macro conditional_error_for_inline_callbacks
\{%
raise ""
%}
end
macro before_save(if _if = nil)
end
end |
It seems I've unearthed some ameba bugs... crystal-ameba/ameba#169 😂 oops.. |
@jwoertink the buggy rule is disabled for a while. I think this work is not blocked anymore by Ameba if you pull the latest master. Thanks for reporting. |
@veelenga cool, thanks! I was mainly keeping it open so we could reference it and use it for a "test ground" if we needed. |
@@ -1,29 +1,77 @@ | |||
module Avram::Callbacks | |||
# :nodoc: | |||
macro conditional_error_for_inline_callbacks(callback, method_name, condition) | |||
\{% |
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.
@jwoertink could you please elaborate on why the leading slash is needed here? I think this is causing the compiler to report the incorrect location.
As I can see from the doc it is used to prevent evaluating a macro the outer macro, which is not the case here.
https://crystal-lang.org/reference/syntax_and_semantics/macros.html#nested-macros
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.
I have the macro interpolation in this, and without the leading slashes, the compile-time error produces the curly brace literals.
# with the leading slash, I get
You must pass a Symbol to `if`
# without the leading slash, I get
You must pass a Symbol to `{{ condition.id }}`
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.
Woops! didn't realize I was still blocking
Sweet! Thanks for the update @matthewmcgarvey. Now that it's using Ameba master, it's all passing. Also looks like the crystal issue was fixed in master, so next release of those will be good again 👍 |
Fixes #483
This PR does 2 things.
skip_*
macros that I just put in the other dayYou can read through the issue for more info, but a quick TL;DR: You can still skip callbacks, it's just done by override a method yourself instead of a macro doing it for you.
This allows us to now do things like this: