class Object

Public Class Methods

_new(*a, &b)
Alias for: new
extended(obj) click to toggle source
Calls superclass method
# File lib/cuts/aop.rb, line 107
def self.extended(obj)
  base = obj.class #__base__

  # use string for 1.9-, and symbol for 1.9+
  methods = obj.methods +
            obj.public_methods +
            obj.protected_methods +
            obj.private_methods -
            [:advices, 'advices']

  methods.uniq.each do |sym|
    #meth = obj.method(sym)
    define_method(sym) do |*args, &blk|
      jp = Joinpoint.new(self, base, sym, *args) #, &blk)
      # calculate advices on first use.
      unless advices[sym]
        advices[sym] = []
        base.aspects.each do |aspect|
          aspect.points.each do |advice, matches|
            matches.each do |match|
              if jp === match
                advices[sym] << [aspect, advice]
              end
            end
          end
        end
      end
      
      if advices[sym].empty?
        super(*args, &blk)
      else
        target = jp #Target.new(self, sym, *args, &blk)  # Target == JoinPoint ?
        advices[sym].each do |(aspect, advice)|
          target = Target.new(aspect, advice, target)
        end
        target.call #super
      end
    end #define_method
  end #methods
end
new(*a, &b) click to toggle source
# File lib/cuts/cut.rb, line 97
def new(*a, &b)
  o = _new(*a, &b)
  if !cuts.empty?
    o.extend *cuts
  end
  o
end
Also aliased as: _new

Public Instance Methods

advices() click to toggle source
# File lib/cuts/aop.rb, line 103
def advices
  @advices ||= {} 
end
cross_cut(klass) click to toggle source
# File lib/cuts/aop.rb, line 95
def cross_cut(klass)

  Cut.new(klass) do

    define_method :__base__ do
      klass 
    end

    def advices
      @advices ||= {} 
    end

    def self.extended(obj)
      base = obj.class #__base__

      # use string for 1.9-, and symbol for 1.9+
      methods = obj.methods +
                obj.public_methods +
                obj.protected_methods +
                obj.private_methods -
                [:advices, 'advices']

      methods.uniq.each do |sym|
        #meth = obj.method(sym)
        define_method(sym) do |*args, &blk|
          jp = Joinpoint.new(self, base, sym, *args) #, &blk)
          # calculate advices on first use.
          unless advices[sym]
            advices[sym] = []
            base.aspects.each do |aspect|
              aspect.points.each do |advice, matches|
                matches.each do |match|
                  if jp === match
                    advices[sym] << [aspect, advice]
                  end
                end
              end
            end
          end
          
          if advices[sym].empty?
            super(*args, &blk)
          else
            target = jp #Target.new(self, sym, *args, &blk)  # Target == JoinPoint ?
            advices[sym].each do |(aspect, advice)|
              target = Target.new(aspect, advice, target)
            end
            target.call #super
          end
        end #define_method
      end #methods
    end #def

  end

end