Class: Aop::Pointcut
- Inherits:
-
Object
- Object
- Aop::Pointcut
- Defined in:
- lib/aop/pointcut.rb
Instance Method Summary collapse
- #advice(&advised) ⇒ Object
-
#initialize(spec) ⇒ Pointcut
constructor
A new instance of Pointcut.
Constructor Details
#initialize(spec) ⇒ Pointcut
Returns a new instance of Pointcut.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/aop/pointcut.rb', line 5 def initialize(spec) @spec = spec @class_spec = spec.scan(/^[^#\.]+/).first || "" @class_names = @class_spec.split(",") @classes = @class_names.map do |name| begin Object.const_get(name) rescue NameError => err raise PointcutNotFound.new(spec, err) end end @method_spec = spec.scan(/[#\.][^,#\.:]+/) @advices = spec.scan(/[^:]:([^:,]+)/).flatten end |
Instance Method Details
#advice(&advised) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/aop/pointcut.rb', line 23 def advice(&advised) return _advice(@advices.first, advised) if @advices.count == 1 @advices.each do |advice| Aop["#{@class_names.join(",")}#{@method_spec.join(",")}:#{advice}"].advice(&advised) end end |