0.0
No commit activity in last 3 years
No release in over 3 years
Easily monitor methods added within classes and modules.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

watch_methods

What is this thing?

Monitor when methods are added to classes or modules and take action when they do.

Why would I want this?

You are:

  • developing a kick-ass gem and you want your users to use your declarative methods before methods are actually defined (think AR validators, callback etc.)
  • Want to monitor all methods starting with queue_ for your new awesome queueing gem.
  • and more!

##Install

[sudo] gem install method_added_hook

Skip all the crap, give me the examples.

Examples

##Usage The method that you'll be interacting with is the watch_methods method that is defined as:

watch_methods(methods, opts={}, &blk)

Where:

  • methods can be a symbol, string, array, regex or any combination. This will be all the methods you want to monitor.

  • opts currently has two optional parameters :class_methods to watch for class methods and :once to only run the given block once for a given method.

  • a given block, which will get run after a given method to watch was added.

Here are some valid uses of watch_methods:

watch_methods(:special_func1, :special_func2) do |meth|

end


# this will watch any class method starting with test_, queue_
watch_methods(/^test_.+$/, /^queue_.+$/, :class _methods => true) do |meth|

end

watch_methods([:meth_one, :meth_two]) do |meth|

 end

or a combination of all of the above:

watch_methods(:special_func, /^test_meth$/, [:meth1, :meth2]) do |meth|

end

To see all examples/cases, see the examples directory and the spec file.

###Supports Ruby 1.8.7, 1.9.2, 1.9.3