callback
Crystal Callback
A Crystal library for defining callbacks.
Installation
Add this to your application's shard.yml
:
dependencies:
callback:
github: mosop/callback
Usage
require "callback"
Callback.enable Reference
class Record
callback!
define_callback_group :save
before :save do
puts "before"
end
around :save do
puts "around"
end
after :save do
puts "after"
end
def save
run_callbacks :save do
puts "yield"
end
end
end
rec = Record.new
rec.save
This prints:
before
around
yield
around
after
For more details, see Wiki
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