Module: CallChain
- Defined in:
- lib/callchain.rb
Instance Method Summary collapse
- #call(thing) ⇒ Object
- #chain ⇒ Object
-
#use(*args) ⇒ Object
CallChain implementations.
Instance Method Details
#call(thing) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/callchain.rb', line 30 def call(thing) return thing unless chain chain.each do |filter| thing = filter.call(thing) yield thing, filter if block_given? end thing end |
#chain ⇒ Object
26 27 28 |
# File 'lib/callchain.rb', line 26 def chain @chain end |
#use(*args) ⇒ Object
CallChain implementations
Individual filters do work with ::call(object)
Compose a CallChain with the ::use method
Compose a CallChain of call chains because it exports ::call(object)
Example:
Pricer = Class.new(CallChain)
class AppTierPricer < Pricer
use PlanScoper, Quantizer, AppGrouper
use UserGrouper
end
21 22 23 24 |
# File 'lib/callchain.rb', line 21 def use(*args) @chain ||= [] @chain.push(*args) end |