callback~drujensen

A Crystal library for defining and invoking callbacks
0.9.2 Latest release released

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"

class Record
  Callback.enable
  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

See Releases.

callback:
  github: drujensen/callback
  version: ~> 0.9.2
License MIT
Crystal >= 0.26.0, < 2.0

Authors

  • mosop

Dependencies 0

Development Dependencies 1

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

Dependents 0

Last synced .
search fire star recently