Skip to content

Commit

Permalink
Fix helpful errors for after_* with block (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith authored Feb 9, 2020
1 parent 7927e16 commit bbe0d2d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/avram/callbacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,35 @@ module Avram::Callbacks
end
end

{% for callbacks_without_block in [:after_save, :after_commit] %}
{% for callback_without_block in [:after_save, :after_commit] %}
# :nodoc:
macro {{ callbacks_without_block.id }}
macro {{ callback_without_block.id }}
\{% raise <<-ERROR
'#{callbacks_without_block.id}' does not accept a block. Instead give it a method name to run.
'{{callback_without_block.id}}' does not accept a block. Instead give it a method name to run.
Example:
#{callbacks_without_block.id} run_something
{{callback_without_block.id}} run_something
def run_something(newly_saved_record)
# Do something
end
ERROR
%}
# Will never be called but must be there so that the macro accepts a block
# Will never be called but must be there so that the macro accepts a block:
\{{ yield }}
end
{% end %}

{% for removed_callback in [:create, :update] %}
# :nodoc:
macro after_{{ removed_callback.id }}(method_name)
\{% raise "'after_#{removed_callback}' has been removed" %}
\{% raise "'after_{{removed_callback.id}}' has been removed" %}
end

# :nodoc:
macro before_{{ removed_callback.id }}(method_name)
\{% raise "'before_#{removed_callback.id}' has been removed" %}
\{% raise "'before_{{removed_callback.id}}' has been removed" %}
end
{% end %}

Expand Down

0 comments on commit bbe0d2d

Please sign in to comment.