Sha256: 313be4c988cbe7cfc5bd125c032e71c3fe98d8205aefb8d7cb7cd75d4efec30a
Contents?: true
Size: 929 Bytes
Versions: 13
Compression:
Stored size: 929 Bytes
Contents
module Spank class Proxy def initialize(target, interceptor_chain = InterceptorChain.new) @target = target @interceptor_chain = interceptor_chain end def add_interceptor(method, interceptor) @interceptor_chain.push(interceptor) self.extend(create_module_for(method)) self end private def create_invocation_for(method, args, block) Invocation.new(@target, method, args, block) end def method_missing(method, *args, &block) if block @target.public_send(method, *args, block) else @target.public_send(method, *args) end end def create_module_for(method) Module.new do define_method(method.to_sym) do |*args, &block| invocation = create_invocation_for(method, args, block) @interceptor_chain.intercept(invocation) invocation.result end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems