Class: Aspector::Base
- Inherits:
-
Object
- Object
- Aspector::Base
- Defined in:
- lib/aspector/base.rb,
lib/aspector/base_class_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#aop_options ⇒ Object
(also: #options)
readonly
Returns the value of attribute aop_options.
-
#aop_target ⇒ Object
(also: #target)
readonly
Returns the value of attribute aop_target.
-
#aop_wrapped_methods ⇒ Object
readonly
Returns the value of attribute aop_wrapped_methods.
Instance Method Summary collapse
- #aop_advices ⇒ Object (also: #advices)
- #aop_apply ⇒ Object (also: #apply)
- #aop_apply_to_method(method, advices, scope = nil) ⇒ Object
- #aop_apply_to_methods ⇒ Object
- #aop_disable ⇒ Object (also: #disable)
- #aop_disabled? ⇒ Boolean
- #aop_enable ⇒ Object (also: #enable)
- #aop_logger ⇒ Object (also: #logger)
- #aop_reset_disabled ⇒ Object (also: #reset_disabled)
- #disabled? ⇒ Boolean
-
#initialize(target, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(target, options = {}) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aspector/base.rb', line 14 def initialize target, = {} @aop_target = target = self.class. if and not .empty? @aop_options = .merge() else @aop_options = end # @aop_context is where advices will be applied (i.e. where methods are modified), can be different from target @aop_context = aop_get_context @aop_wrapped_methods = {} after_initialize end |
Instance Attribute Details
#aop_options ⇒ Object (readonly) Also known as: options
Returns the value of attribute aop_options.
6 7 8 |
# File 'lib/aspector/base.rb', line 6 def @aop_options end |
#aop_target ⇒ Object (readonly) Also known as: target
Returns the value of attribute aop_target.
9 10 11 |
# File 'lib/aspector/base.rb', line 9 def aop_target @aop_target end |
#aop_wrapped_methods ⇒ Object (readonly)
Returns the value of attribute aop_wrapped_methods.
12 13 14 |
# File 'lib/aspector/base.rb', line 12 def aop_wrapped_methods @aop_wrapped_methods end |
Instance Method Details
#aop_advices ⇒ Object Also known as: advices
71 72 73 |
# File 'lib/aspector/base.rb', line 71 def aop_advices self.class.aop_advices end |
#aop_apply ⇒ Object Also known as: apply
76 77 78 79 80 81 82 83 84 |
# File 'lib/aspector/base.rb', line 76 def aop_apply before_apply aop_invoke_deferred_logics aop_define_methods_for_advice_blocks aop_add_to_instances unless @aop_options[:old_methods_only] aop_apply_to_methods unless @aop_options[:new_methods_only] aop_add_method_hooks unless @aop_options[:old_methods_only] after_apply end |
#aop_apply_to_method(method, advices, scope = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/aspector/base.rb', line 119 def aop_apply_to_method method, advices, scope = nil advices = aop_filter_advices advices, method return if advices.empty? aop_logger.log Logger::APPLY_TO_METHOD, method before_apply_to_method method, advices scope ||= if @aop_context.private_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s) :private elsif @aop_context.protected_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s) :protected else :public end aop_recreate_method method, advices, scope after_apply_to_method method, advices end |
#aop_apply_to_methods ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aspector/base.rb', line 87 def aop_apply_to_methods advices = aop_advices # If method/methods option is set and all are String or Symbol, apply to those only, instead of # iterating through all methods methods = [@aop_options[:method] || @aop_options[:methods]] methods.compact! methods.flatten! if not methods.empty? and methods.all?{|method| method.is_a? String or method.is_a? Symbol } methods.each do |method| aop_apply_to_method(method.to_s, advices) end return end @aop_context.public_instance_methods.each do |method| aop_apply_to_method(method.to_s, advices, :public) end @aop_context.protected_instance_methods.each do |method| aop_apply_to_method(method.to_s, advices, :protected) end if @aop_options[:private_methods] @aop_context.private_instance_methods.each do |method| aop_apply_to_method(method.to_s, advices, :private) end end end |
#aop_disable ⇒ Object Also known as: disable
41 42 43 44 45 46 47 |
# File 'lib/aspector/base.rb', line 41 def aop_disable class << self def aop_disabled?; true; end end aop_disabled? end |
#aop_disabled? ⇒ Boolean
59 60 |
# File 'lib/aspector/base.rb', line 59 def aop_disabled? end |
#aop_enable ⇒ Object Also known as: enable
32 33 34 35 36 37 38 |
# File 'lib/aspector/base.rb', line 32 def aop_enable class << self def aop_disabled?; end end aop_disabled? end |
#aop_logger ⇒ Object Also known as: logger
66 67 68 |
# File 'lib/aspector/base.rb', line 66 def aop_logger @aop_logger ||= Logger.new(self, self.class.logger.level) end |
#aop_reset_disabled ⇒ Object Also known as: reset_disabled
50 51 52 53 54 55 56 |
# File 'lib/aspector/base.rb', line 50 def aop_reset_disabled class << self remove_method :aop_disabled? end aop_disabled? end |
#disabled? ⇒ Boolean
62 63 64 |
# File 'lib/aspector/base.rb', line 62 def disabled? aop_disabled? end |