Popularity
3.5
Declining
Activity
0.0
Stable
12
3
1

Programming language: Crystal
License: MIT License
Tags: Misc    
Latest version: v0.2.0

callbacks alternatives and similar shards

Based on the "Misc" category.
Alternatively, view callbacks alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of callbacks or a related project?

Add another 'Misc' Shard

README

Callbacks

Built with Crystal Build status Docs Releases Awesome vladfaust.com Patrons count Gitter chat

An expressive callbacks module for Crystal.

Supporters

Thanks to all my patrons, I can build and support beautiful Open Source Software! ๐Ÿ™

Lauri Jutila, Alexander Maslov, Dainel Vera

You can become a patron too in exchange of prioritized support and other perks

Become Patron

About

Callbacks defined with this module are properly inherited and run within a scope of the object itself (i.e. have an access to instance variables etc.).

Installation

Add this to your application's shard.yml:

dependencies:
  callbacks:
    github: vladfaust/callbacks.cr
    version: ~> 0.2.0

This shard follows Semantic Versioning 2.0.0, so see releases and change the version accordingly.

Usage

require "callbacks"

class Foo
  include Callbacks

  def call
    with_callbacks { puts "call" }
  end

  before do
    puts "1"
  end

  before do
    puts "2"
  end

  after do
    puts "3"
  end

  after do
    puts "4"
  end
end

Foo.new.call
# 1, 2, call, 3, 4

Objects including Callbacks module can also be inherited preserving all callbacks:

class Bar < Foo
  # Childrens before callbacks have higher precedence
  before do
    puts "5"
  end

  # Childrens after callbacks executed after parents'
  after do
    puts "6"
  end
end

Bar.new.call
# 5, 1, 2, call, 3, 4, 6

Contributing

  1. Fork it (https://github.com/vladfaust/callbacks.cr/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

Contributors