Class: Aspekt::Advice

Inherits:
Object
  • Object
show all
Defined in:
lib/aspekt.rb

Instance Method Summary collapse

Methods inherited from Object

all

Constructor Details

#initialize(opts) ⇒ Advice

Example usage

advice = Aspekt::Advice.new ( type: :before, pointcut: pointcut ) do |joinpoint|
  puts "before #{joinpoint}"
end

advice = Aspekt::Advice.new ( type: :around, pointcuts: [pointcut1, pointcut2]) do |joinpoint|
  puts "around :start for #{joinpoint}"
  return_value = joinpoint.proceed
  puts "around :end for #{joinpoint}"
end

Raises:

  • (ArgumentError)


124
125
126
127
128
129
# File 'lib/aspekt.rb', line 124

def initialize opts
  opts[:pointcuts] = [opts.delete(:pointcut)].flatten if opts[:pointcut]
  super opts
  raise ArgumentError, "type has to be Symbol: before, after or around" unless [:before, :after, :around].include?(self[:type])
  raise ArgumentError, "no pointcut defined" unless self[:pointcuts].length   
end