Module: Aspector::Base::ClassMethods

Extended by:
ClassMethods
Included in:
ClassMethods
Defined in:
lib/aspector/base_class_methods.rb

Instance Method Summary collapse

Instance Method Details

#aop_advicesObject Also known as: advices



38
39
40
# File 'lib/aspector/base_class_methods.rb', line 38

def aop_advices
  @aop_advices ||= []
end

#aop_after(*methods, &block) ⇒ Object Also known as: after



88
89
90
91
92
93
# File 'lib/aspector/base_class_methods.rb', line 88

def aop_after *methods, &block
  aop_advices << advice = aop_create_advice(Aspector::AdviceMetadata::AFTER, self, methods, &block)
  advice.index = aop_advices.size
  aop_logger.log Logging::INFO, 'define-advice', advice
  advice
end

#aop_apply(target, *rest) ⇒ Object Also known as: apply



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aspector/base_class_methods.rb', line 48

def aop_apply target, *rest
  options = rest.last.is_a?(Hash) ? rest.pop : {}

  targets = rest.unshift target
  result = targets.map do |target|
    aop_logger.log Logging::INFO, 'apply', target, options.inspect
    aspect_instance = new(target, options)
    aspect_instance.send :aop_apply
    aspect_instance
  end

  result.size == 1 ? result.first : result
end

#aop_around(*methods, &block) ⇒ Object Also known as: around



96
97
98
99
100
101
# File 'lib/aspector/base_class_methods.rb', line 96

def aop_around *methods, &block
  aop_advices << advice = aop_create_advice(Aspector::AdviceMetadata::AROUND, self, methods, &block)
  advice.index = aop_advices.size
  aop_logger.log Logging::INFO, 'define-advice', advice
  advice
end

#aop_before(*methods, &block) ⇒ Object Also known as: before



72
73
74
75
76
77
# File 'lib/aspector/base_class_methods.rb', line 72

def aop_before *methods, &block
  aop_advices << advice = aop_create_advice(Aspector::AdviceMetadata::BEFORE, self, methods, &block)
  advice.index = aop_advices.size
  aop_logger.log Logging::INFO, 'define-advice', advice
  advice
end

#aop_before_filter(*methods, &block) ⇒ Object Also known as: before_filter



80
81
82
83
84
85
# File 'lib/aspector/base_class_methods.rb', line 80

def aop_before_filter *methods, &block
  aop_advices << advice = aop_create_advice(Aspector::AdviceMetadata::BEFORE_FILTER, self, methods, &block)
  advice.index = aop_advices.size
  aop_logger.log Logging::INFO, 'define-advice', advice
  advice
end

#aop_default(options) ⇒ Object Also known as: default



63
64
65
66
67
68
69
# File 'lib/aspector/base_class_methods.rb', line 63

def aop_default options
  if @aop_default_options
    @aop_default_options.merge! options
  else
    @aop_default_options = options
  end
end

#aop_default_optionsObject Also known as: default_options



43
44
45
# File 'lib/aspector/base_class_methods.rb', line 43

def aop_default_options
  @aop_default_options ||= {}
end

#aop_disableObject Also known as: disable



15
16
17
18
19
20
21
22
# File 'lib/aspector/base_class_methods.rb', line 15

def aop_disable
  aop_logger.log Logging::INFO, 'disable-aspect'
  send :define_method, :aop_disabled? do
    true
  end

  nil
end

#aop_enableObject Also known as: enable



6
7
8
9
10
11
12
# File 'lib/aspector/base_class_methods.rb', line 6

def aop_enable
  aop_logger.log Logging::INFO, 'enable-aspect'
  send :define_method, :aop_disabled? do
  end

  nil
end

#aop_loggerObject Also known as: logger

if ENV is set, use it else try to load logem and use Logem::Logger else use built in logger



28
29
30
# File 'lib/aspector/base_class_methods.rb', line 28

def aop_logger
  @aop_logger ||= Logging.get_logger(self)
end

#aop_logger=(logger) ⇒ Object Also known as: logger=



33
34
35
# File 'lib/aspector/base_class_methods.rb', line 33

def aop_logger= logger
  @aop_logger = logger
end

#aop_optionsObject Also known as: options



121
122
123
# File 'lib/aspector/base_class_methods.rb', line 121

def aop_options
  DeferredOption.new
end

#aop_raw(*methods, &block) ⇒ Object Also known as: raw



104
105
106
107
108
109
# File 'lib/aspector/base_class_methods.rb', line 104

def aop_raw *methods, &block
  aop_advices << advice = aop_create_advice(Aspector::AdviceMetadata::RAW, self, methods, &block)
  advice.index = aop_advices.size
  aop_logger.log Logging::INFO, 'define-advice', advice
  advice
end

#aop_target(code = nil, &block) ⇒ Object Also known as: target



112
113
114
115
116
117
118
# File 'lib/aspector/base_class_methods.rb', line 112

def aop_target code = nil, &block
  return unless code or block_given?

  logic = DeferredLogic.new(code || block)
  aop_deferred_logics << logic
  logic
end