callback

A library for defining and invoking callbacks
0.3.0 released
mosop/callback
10 2 1
mosop

Crystal Callback

A Crystal library for defining and invoking callbacks.

Build Status

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

  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

Contributing

  1. Fork it ( https://github.com/mosop/callback/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
callback:
  github: mosop/callback
  version: ~> 0.3.0
License MIT
Crystal none

Authors

  • mosop

Dependencies 0

Development Dependencies 1

  • stdio ~> 0.1.3
    {'github' => 'mosop/stdio', 'version' => '~> 0.1.3'}

Dependents 1

Last synced .
search fire star recently