Sha256: 55b504d6f536b873908dddc6ec988d855efc6431aee115d7b3a376be358dd983

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

class Module
  def included_with_a4r(base)
    included_without_a4r(base)
    
    return if @a4r_data.nil? or @a4r_data.empty?
  
    base.send(:include, Aspect4r)
    
    existing_aspects = base.a4r_data
    existing_aspects.methods_with_advices.merge(@a4r_data.methods_with_advices)    
  end
  
  alias included_without_a4r included
  alias included             included_with_a4r
  
  def method_added_with_a4r(method)
    method_added_without_a4r(method)
    
    return if method.to_s =~ /a4r/

    # save unbound method and create new method
    if @a4r_data and method_advices = @a4r_data[method] and not Aspect4r::Helper.creating_method?
      method_advices.wrapped_method = instance_method(method)
      Aspect4r::Helper.create_method self, method
    end
  end
  
  alias method_added_without_a4r method_added
  alias method_added             method_added_with_a4r

  def singleton_method_added_with_a4r(method)
    singleton_method_added_without_a4r(method)
    
    return if method.to_s =~ /a4r/

    # save unbound method and create new method
    eigen_class = Aspect4r::Helper.eigen_class(self)
    my_advices  = eigen_class.instance_variable_get(:@a4r_data)
    
    if my_advices and method_advices = my_advices[method] and not Aspect4r::Helper.creating_method?
      method_advices.wrapped_method = eigen_class.instance_method(method)
      Aspect4r::Helper.create_method eigen_class, method
    end
  end
  
  alias singleton_method_added_without_a4r singleton_method_added
  alias singleton_method_added             singleton_method_added_with_a4r
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aspect4r-0.8.1 lib/aspect4r/extensions/module_extension.rb
aspect4r-0.8.0 lib/aspect4r/extensions/module_extension.rb