module Wrap
Constants
- ClassMethods
- InstanceMethods
- Version
Public Class Methods
code_for(method)
click to toggle source
# File lib/wrap.rb, line 48 def Wrap.code_for(method) name = method.name.to_s arity = method.arity case when arity == 0 signature = <<-__.strip def #{ name }(&block) args = [] __ when arity < 0 argv = Array.new(arity.abs - 1){|i| "arg#{ i }"} argv.push('*args') argv = argv.join(', ') signature = <<-__.strip def #{ name }(#{ argv }, &block) args = [#{ argv }] __ when arity > 0 argv = Array.new(arity){|i| "arg#{ i }"} argv = argv.join(', ') signature = <<-__.strip def #{ name }(#{ argv }, &block) args = [#{ argv }] __ end code = <<-__ #{ signature.strip } if running_callbacks?(#{ name.inspect }) return wrapped_#{ name }(*args, &block) end running_callbacks(#{ name.inspect }) do catch(:halt) do return false if run_callbacks(:before, #{ name.inspect }, args)==false begin result = wrapped_#{ name }(*args, &block) ensure run_callbacks(:after, #{ name.inspect }, [result]) unless $! end end end end __ end
dependencies()
click to toggle source
# File lib/wrap.rb, line 14 def dependencies { 'map' => [ 'map' , ' >= 4.7.1' ] } end
description()
click to toggle source
# File lib/wrap.rb, line 20 def description 'non-sucking :before and :after filters for any ruby class' end
included(other)
click to toggle source
Calls superclass method
# File lib/wrap.rb, line 41 def Wrap.included(other) super ensure other.send(:instance_eval, &ClassMethods) other.send(:class_eval, &InstanceMethods) end
version()
click to toggle source
# File lib/wrap.rb, line 10 def version Wrap::Version end