Callchain
TODO: Write a gem description
Installation
Add this line to your application's Gemfile:
gem 'callchain'
And then execute:
$ bundle
Or install it yourself as:
$ gem install callchain
Usage
Individual objects, lambdas, or modules do work with ::call(object)
Compose a CallChain with the ::use method
Compose a CallChain of call chains because it exports ::call(object)
Example: Class/Module names define ::call
class PlanScoper
def self.call(thing)
scope_the_thing(thing)
thing
end
end
module Quantizer
def self.call(thing)
quantize_the_thing(thing)
thing
end
end
class Pricer
extend CallChain
use PlanScoper, Quantizer, AppGrouper
use UserGrouper
end
statement = Statement.new
Pricer.call(statement)
Example: lambda-friendly
class Debugger
extend CallChain
use lambda { |thing| p thing; thing }
end
Debugger.call(Object.new)
Example: composable
class CompositeCallChain
extend CallChain
use Debugger
end
CompositeCallChain.call(Object.new)
CallChain::bind
class WrapToI
extend CallChain
use CallChain[:to_i]
end
WrapToI.call('1')
# => 1
class WrapToI
extend CallChain
use CallChain.bind(:+, 1)
end
WrapToI.call(1)
# => 2
Contributing
- Fork it ( http://github.com/
/callchain/fork ) - 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