From 1709df676ae300c9428af3d20420a90af519f8ab Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 17 Sep 2019 14:57:38 -0700 Subject: [PATCH 1/3] Add compile-time error to catch use of before in SaveOperation. --- src/avram/callbacks.cr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/avram/callbacks.cr b/src/avram/callbacks.cr index ef21e1faa..47d7e0d1c 100644 --- a/src/avram/callbacks.cr +++ b/src/avram/callbacks.cr @@ -125,4 +125,18 @@ module Avram::Callbacks \{% raise "'before_#{removed_callback.id}' has been removed" %} end {% end %} + + # :nodoc: + macro before(unused) + {% raise <<-ERROR + + 'before' is not a valid SaveOperation callback. + + Try this... + + ▸ before_save #{ unused.id } + + ERROR + %} + end end From f7eb5f52c27840574964a807f221fc9cda39a968 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 17 Sep 2019 15:03:26 -0700 Subject: [PATCH 2/3] little variable rename for clarity --- src/avram/callbacks.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/avram/callbacks.cr b/src/avram/callbacks.cr index 47d7e0d1c..5607bb260 100644 --- a/src/avram/callbacks.cr +++ b/src/avram/callbacks.cr @@ -127,14 +127,14 @@ module Avram::Callbacks {% end %} # :nodoc: - macro before(unused) + macro before(callback_method) {% raise <<-ERROR 'before' is not a valid SaveOperation callback. Try this... - ▸ before_save #{ unused.id } + ▸ before_save #{ callback_method.id } ERROR %} From fa4ce5c08a3dd2808e140d95935c5e705a28a4f1 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 17 Sep 2019 15:04:03 -0700 Subject: [PATCH 3/3] forgot to format --- src/avram/callbacks.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/avram/callbacks.cr b/src/avram/callbacks.cr index 5607bb260..ca89eb224 100644 --- a/src/avram/callbacks.cr +++ b/src/avram/callbacks.cr @@ -134,7 +134,7 @@ module Avram::Callbacks Try this... - ▸ before_save #{ callback_method.id } + ▸ before_save #{callback_method.id} ERROR %}