Advisable

In Files

Namespace

Class Index [+]

Quicksearch
Generated with Razzle Dazzle Redfish.
[Validate]

Advisable

Advisable provides a means of using before, after and around adivce.

Public Instance Methods

advice_after() click to toggle source

(Not documented)

# File lib/advisable.rb, line 37
  def advice_after
    @advice_after ||= {} #Hash.new{|h,k| h[k] = []}
  end
advice_around() click to toggle source

(Not documented)

# File lib/advisable.rb, line 41
  def advice_around
    @advice_around ||= {} #Hash.new{|h,k| h[k] = []}
  end
advice_before() click to toggle source

(Not documented)

# File lib/advisable.rb, line 33
  def advice_before
    @advice_before ||= {} #Hash.new{|h,k| h[k] = []}
  end
advise(meth) click to toggle source

Advise a method.

# File lib/advisable.rb, line 65
  def advise(meth)
    #return false if defined?(meth_origin)
    args = instance_method(meth).arguments

    module_eval("alias_method '\#{meth}_origin', '\#{meth}'\ndef \#{meth}(\#{args})\ntarget = method!('\#{meth}_origin')\n\nunless target.advised\nancs = self.class.ancestors.select{ |anc| anc.respond_to?(:advice_before) }\ntarget.advice_before = ancs.collect{ |anc| anc.advice_before[:'\#{meth}'] }\ntarget.advice_after  = ancs.collect{ |anc| anc.advice_after[:'\#{meth}'] }\ntarget.advice_around = ancs.collect{ |anc| anc.advice_around[:'\#{meth}'] }\ntarget.advised = true\nend\n\ntarget.call_with_advice(self, *[\#{args}])\nend\n", __FILE__, __LINE__)
  end
after(meth, &block) click to toggle source

(Not documented)

# File lib/advisable.rb, line 51
  def after(meth, &block)
    name = "#{meth}:after#{block.object_id}"
    define_method(name, &block)
    (advice_after[meth.to_sym] ||= []) << name
  end
around(meth, &block) click to toggle source

(Not documented)

# File lib/advisable.rb, line 57
  def around(meth, &block)
    name = "#{meth}:around#{block.object_id}"
    define_method(name, &block)
    (advice_around[meth.to_sym] ||= []) << name
  end
before(meth, &block) click to toggle source

(Not documented)

# File lib/advisable.rb, line 45
  def before(meth, &block)
    name = "#{meth}:before#{block.object_id}"
    define_method(name, &block)
    (advice_before[meth.to_sym] ||= []) << name
  end
method_added(meth) click to toggle source

after :method_added do |meth|

  advise(meth) unless defined?("#{meth}_orig")

end

# File lib/advisable.rb, line 94
  def method_added(meth)
    return if meth == :method_added
    @added_stack ||= []
    return if @added_stack.last == meth
    return if /_(origin)$/ =~ meth.to_s
    return if /:(before|after|around)/ =~ meth.to_s
    @added_stack << meth
    #return if instance_methods(false).include?("#{meth}_orig")
    advise(meth)
    @added_stack.pop
  end

Disabled; run with --debug to generate this.