[ANN] HookR 1.0.0

I’m pleased to announce the availability of “HookR”:http://hookr.rubyforge.org 1.0.0

h2. Description

HookR is a publish/subscribe callback hook facility for Ruby.

h2. What is it?

HookR can be understood in a few different ways.

  • If you are familiar with Events and Event Listeners in “Java”:http://java.sun.com/docs/books/tutorial/javabeans/events/index.html or “C#”:http://msdn.microsoft.com/en-us/library/aa645739(VS.71).aspx; “Hooks”:http://www.gnu.org/software/emacs/manual/html_node/elisp/Hooks.html#Hooks in Emacs-lisp; or signals-and-slots as implemented in the “Qt”:http://doc.trolltech.com/4.4/signalsandslots.html, “Boost.Signals”:http://www.boost.org/doc/libs/1_37_0/doc/html/signals.html, or “libsigc++”:http://libsigc.sourceforge.net/ frameworks – HookR provides a very similar facility.
  • If you’ve ever used the Observer standard library, but wished you could have more than one type of notification per observable object, HookR is the library for you.
  • HookR is an easy way to add “Rails-style”:http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html before- and after-filters to your own classes.
  • HookR is an “Inversion-of-Control”:http://martinfowler.com/bliki/InversionOfControl.html framework in that it makes it easy to write event-driven code.
  • HookR is a way to support a limited, structured form of Aspect Oriented Programming (“AOP”:http://en.wikipedia.org/wiki/Aspect-oriented_programming) where the advisable events are explicitly defined.

h2. What HookR is not:

  • HookR is not (yet) an asynchronous event notification system. No provision is made for multi-threaded operation or event queueing.
  • HookR will show you a good time, but it will not make you breakfast in the morning.

h2. Synopsis

  require 'rubygems'
  require 'hookr'

  class ZeroWing
    include HookR::Hooks
    define_hook :we_get_signal, :message

    def start_game
      execute_hook(:we_get_signal, "How are you gentlemen?")
    end

    def bomb(event, message)
      puts "somebody set us up the bomb!"
      puts "All of your hookrs are belong to us!!!"
    end

    we_get_signal do |event, message|
      puts "Main screen turn on!"
      puts "Cats: #{message}"
    end

    we_get_signal :bomb

  end

  zw = ZeroWing.new
  zw.we_get_signal do
    puts "Take off every zig!"
  end

  zw.start_game
  # >> Main screen turn on!
  # >> Cats: How are you gentlemen?
  # >> somebody set us up the bomb!
  # >> Take off every zig!

h2. Get it Now

Pull your hat way down over your eyes, drive over to the your local red-light district, and type:

sudo gem install hookr

For more information, check out the website: http://hookr.rubyforge.org

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *