catchy: Instantly appealing and memorable, a gem to capture chains of method calls.
Add this line to your application's Gemfile:
gem 'catchy'
And then execute:
$ bundle
Or install it yourself as:
$ gem install catchy
At it's simplest you just instantiate a new Catchy
and give it to whatever you want to capture the calls of:
proxy = Catchy.new
object.black_box( proxy )
Then you can get the chain of called methods as a string:
proxy.to_s # => "some.chain.of.method.calls"
"But what if I need to capture call chains that include calls to to_s?" I hear you saying. Ah, we thought of that. Simply tell Catchy
that you want another name for to_s
when you create it, like this:
proxy = Catchy.new(to_s: :__to_string__)
or with a config block, handy for a Rails initializer or similar, like this:
# config/initializers/catchy.rb
Catchy.configure do |config|
config.to_s = :__to_string__
end
# app/whatever/class.rb
proxy = Catchy.new
Then you can use it like this:
proxy.call.whatever.you.want.to_s
...
proxy.__to_string__
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
To Hüseyin Öztürk for suggesting the name. Originally the gem was called MethodChainProxy, but mr Öztürk found it less than sexy and suggested: "something funny and relevant, catchy ..." so there we where, Catchy. Exellent work!