Project

crochets

0.0
No commit activity in last 3 years
No release in over 3 years
Easy setting of hook chains on Ruby methods calls in rubtime
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Crochets

Build Status

This gem is kinda syntactic sugar for setting hooks on ruby method calls.

It uses Aquarium for aspects.

Installation

Add this line to your application's Gemfile:

gem 'crochets'

And then execute:

$ bundle

Or install it yourself as:

$ gem install crochets

Usage

The usage is straightforward:

class MyClass
  def my_method
    puts "Hello, world!"
  end
end
    
@aspect = Crochets.hook(MyClass, :my_method, after: true, blocking: false) do |obj, *args|
  puts "NB: world is now helloed."
end

# ⇒ Hello, world!
# ⇒ NB: world is now helloed.

The hook may then be unset:

@aspect.unhook

There are many hooks on the same method may be set simultaneously. They will be invoked in the order they were set.

Arguments

The method Crochets::Crocheter#hook accepts following parameters:

  • object or class [Class|Object] the object or class to set the hook on;
  • method Symbol the name of the method to set the hook on, or :all_methods
  • after [TrueClass|FalseClass] apply the hook after method body execution
  • before [TrueClass|FalseClass] apply the hook before method body execution
  • blocking [TrueClass|FalseClass] when false, the hook will be executed in the separate thread.

Contributing

  1. Fork it
  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 new Pull Request