Class: CoAspects::Attacher

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

Instance Method Summary collapse

Constructor Details

#initializeAttacher

Returns a new instance of Attacher.



5
6
7
# File 'lib/co_aspects/attacher.rb', line 5

def initialize
  @pending = []
end

Instance Method Details

#add(method_name, options, block) ⇒ Object



9
10
11
12
# File 'lib/co_aspects/attacher.rb', line 9

def add(method_name, options, block)
  aspect_class = aspect_from_method(method_name)
  @pending << Annotation.new(aspect_class, options, block)
end

#attach(klass, method_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/co_aspects/attacher.rb', line 14

def attach(klass, method_name)
  blocking do
    @pending.each do |pending|
      pending.aspect.apply klass,
        method: method_name,
        annotation: pending.options,
        block: pending.block
    end
    @pending = []
  end
end