callback
Crystal Callback
A Crystal library for defining and invoking callbacks.
Installation
Add this to your application's shard.yml
:
dependencies:
callback:
github: mosop/callback
Usage
require "callback"
Callback.enable Reference
class Record
Callback.callback!
define_callback_group :save
before_save do
puts "before"
end
around_save do
puts "around"
end
after_save do
puts "after"
end
on_save do
puts "on"
end
def save
run_callbacks_for_save do
puts "yield"
end
end
end
rec = Record.new
rec.save
This prints:
before
around
on
yield
around
after
For more detail, see Wiki
Release Notes
- v0.4.0
- Callback.enable no longer receives a class argument. Use Callback.enable inside a class instead.
Contributing
- Fork it ( https://github.com/mosop/callback/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request