Module: Aspect4r::Base::ClassMethods

Defined in:
lib/aspect4r/base.rb

Instance Method Summary collapse

Instance Method Details

#a4r_dataObject



54
55
56
# File 'lib/aspect4r/base.rb', line 54

def a4r_data
  @a4r_data ||= Aspect4r::Model::AspectData.new(self)
end

#a4r_disable_advices_temporarily(*methods) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/aspect4r/base.rb', line 67

def a4r_disable_advices_temporarily *methods
  methods.each do |method|
    method = method.to_s
    advices = a4r_data.advices_for_method(method)
    next if advices.empty?
    
    send :alias_method, :"#{method}_with_advices", method
    Aspect4r::Helper.define_method self, method, a4r_data.wrapped_methods[method]
  end
  
  yield
ensure
  methods.each do |method|
    method_with_advices = "#{method}_with_advices"
    next unless instance_methods.include?(method_with_advices)

    send :alias_method, method, method_with_advices
    self.send :remove_method, method_with_advices
  end
end

#a4r_group(&block) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/aspect4r/base.rb', line 58

def a4r_group &block
  a4r_data.change_group
  
  if block_given?
    instance_eval &block
    a4r_data.change_group
  end
end

#method_added(method) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aspect4r/base.rb', line 20

def method_added method
  super method

  return if Aspect4r::Helper.creating_method?

  method = method.to_s
  return if method[0..2] == "a4r"

  # save unbound method and create new method
  advices = a4r_data.advices_for_method(method)
  unless advices.empty?
    a4r_data.wrapped_methods[method] = instance_method(method)
    Aspect4r::Helper.create_method self, method
  end
end

#singleton_method_added(method) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/aspect4r/base.rb', line 36

def singleton_method_added method
  super method

  return if Aspect4r::Helper.creating_method?
    
  method = method.to_s
  return if method[0..2] == "a4r"

  eigen_class = class << self; self; end

  # save unbound method and create new method
  advices = eigen_class.a4r_data.advices_for_method(method)
  unless advices.empty?
    eigen_class.a4r_data.wrapped_methods[method] = eigen_class.instance_method(method)
    Aspect4r::Helper.create_method eigen_class, method
  end
end