Skip to content
Browse files

Clean up api

  • Loading branch information...
1 parent a631bd0 commit 56742118f38d12cdad3c5b7a4e451264f563cb62 @gcao committed Jan 2, 2013
View
8 lib/aspector/advice.rb
@@ -61,10 +61,6 @@ def around?
type == AROUND
end
- def invoke obj, *args, &block
- obj.send with_method, *args, &block
- end
-
def type_name
case @type
when BEFORE then @options[:skip_if_false] ? "BEFORE_FILTER" : "BEFORE"
@@ -74,6 +70,10 @@ def type_name
else "UNKNOWN?!"
end
end
+
+ def use_deferred_logic? logic
+ method_matcher.use_deferred_logic? logic
+ end
def to_s
s = "#{name}: "
View
4 lib/aspector/aspect_instances.rb
@@ -3,8 +3,8 @@ class AspectInstances < Array
def apply_to_method method
each do |aspect_instance|
- next if aspect_instance.aop_options[:old_methods_only]
- aspect_instance.aop_apply_to_method method, aspect_instance.aop_advices
+ next if aspect_instance.options[:old_methods_only]
+ aspect_instance.apply_to_method method
end
end
View
300 lib/aspector/base.rb
@@ -3,229 +3,167 @@
module Aspector
class Base
- attr :aop_options
- alias options aop_options
-
- attr :aop_target
- alias target aop_target
-
- attr :aop_wrapped_methods
+ attr :target
+ attr :options
def initialize target, options = {}
- @aop_target = target
+ @target = target
- default_options = self.class.aop_default_options
+ default_options = self.class.default_options
if default_options and not default_options.empty?
- @aop_options = default_options.merge(options)
+ @options = default_options.merge(options)
else
- @aop_options = 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
-
- def aop_enable
- class << self
- def aop_disabled?; end
+ @options = options
end
- aop_disabled?
- end
- alias enable aop_enable
-
- def aop_disable
- class << self
- def aop_disabled?; true; end
- end
-
- aop_disabled?
- end
- alias disable aop_disable
-
- def aop_reset_disabled
- class << self
- remove_method :aop_disabled?
- end
-
- aop_disabled?
- end
- alias reset_disabled aop_reset_disabled
-
- def aop_disabled?
+ @wrapped_methods = {}
end
def disabled?
- aop_disabled?
+ # Enabled by default
end
- def aop_logger
- return @aop_logger if @aop_logger
+ def logger
+ return @logger if @logger
- @aop_logger = Logging.get_logger(self)
- @aop_logger.level = self.class.logger.level
- @aop_logger
+ @logger = Logging.get_logger(self)
+ @logger.level = self.class.logger.level
+ @logger
end
- alias logger aop_logger
- def aop_advices
- self.class.aop_advices
+ def advices
+ self.class.advices
end
- alias advices aop_advices
-
- 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]
+
+ def apply
+ invoke_deferred_logics
+ define_methods_for_advice_blocks
+ add_to_instances unless @options[:old_methods_only]
+ apply_to_methods unless @options[:new_methods_only]
+ add_method_hooks unless @options[:old_methods_only]
# TODO: clear deferred logic results if they are not used in any advice
- after_apply
end
- alias apply aop_apply
- def aop_apply_to_methods
- return if aop_advices.empty?
-
- advices = aop_advices
+ def apply_to_methods
+ return if advices.empty?
# 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 = [@options[:method] || @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)
+ apply_to_method(method.to_s)
end
return
end
- @aop_context.public_instance_methods.each do |method|
- aop_apply_to_method(method.to_s, advices, :public)
+ context.public_instance_methods.each do |method|
+ apply_to_method(method.to_s, :public)
end
- @aop_context.protected_instance_methods.each do |method|
- aop_apply_to_method(method.to_s, advices, :protected)
+ context.protected_instance_methods.each do |method|
+ apply_to_method(method.to_s, :protected)
end
- if @aop_options[:private_methods]
- @aop_context.private_instance_methods.each do |method|
- aop_apply_to_method(method.to_s, advices, :private)
+ if @options[:private_methods]
+ context.private_instance_methods.each do |method|
+ apply_to_method(method.to_s, :private)
end
end
end
- def aop_apply_to_method method, advices, scope = nil
- advices = aop_filter_advices advices, method
- return if advices.empty?
+ def apply_to_method method, scope = nil
+ filtered_advices = filter_advices advices, method
+ return if filtered_advices.empty?
- aop_logger.log Logging::DEBUG, 'apply-to-method', method
- before_apply_to_method method, advices
+ logger.log Logging::DEBUG, 'apply-to-method', method
scope ||=
- if @aop_context.private_instance_methods.include?(RUBY_VERSION.index('1.9') ? method.to_sym : method.to_s)
+ if 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)
+ elsif 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
-
- protected
-
- # Hook method that runs after an aspect is instantiated
- def after_initialize
- end
-
- # Hook method that runs before an aspect is applied
- def before_apply
+ recreate_method method, filtered_advices, scope
end
- # Hook method that runs after an aspect is applied
- def after_apply
- end
+ private
- def before_apply_to_method method, advices
+ def deferred_logic_results logic
+ @deferred_logic_results[logic]
end
- def after_apply_to_method method, advices
+ def get_wrapped_method_of method
+ @wrapped_methods[method]
end
- private
-
- def aop_deferred_logic_results logic
- @aop_deferred_logic_results[logic]
- end
+ # context is where advices will be applied (i.e. where methods are modified), can be different from target
+ def context
+ return @target if @target.is_a?(Module) and not @options[:class_methods]
- def aop_get_context
- return @aop_target if @aop_target.is_a?(Module) and not @aop_options[:class_methods]
-
- class << @aop_target
+ class << @target
self
end
end
- def aop_invoke_deferred_logics
- return unless (logics = self.class.send :aop_deferred_logics)
+ def invoke_deferred_logics
+ return unless (logics = self.class.send :_deferred_logics_)
- @aop_deferred_logic_results ||= {}
logics.each do |logic|
- @aop_deferred_logic_results[logic] = logic.apply @aop_context, self
+ result = logic.apply context, self
+ if advices.detect {|advice| advice.use_deferred_logic? logic }
+ @deferred_logic_results ||= {}
+ @deferred_logic_results[logic] = result
+ end
end
end
- def aop_define_methods_for_advice_blocks
- aop_advices.each do |advice|
+ def define_methods_for_advice_blocks
+ advices.each do |advice|
next if advice.raw?
next unless advice.advice_block
- @aop_context.send :define_method, advice.with_method, advice.advice_block
- @aop_context.send :private, advice.with_method
+ context.send :define_method, advice.with_method, advice.advice_block
+ context.send :private, advice.with_method
end
end
- def aop_add_to_instances
- return if aop_advices.empty?
+ def add_to_instances
+ return if advices.empty?
- aspect_instances = @aop_context.instance_variable_get(:@aop_instances)
+ aspect_instances = context.instance_variable_get(:@aop_instances)
unless aspect_instances
aspect_instances = AspectInstances.new
- @aop_context.instance_variable_set(:@aop_instances, aspect_instances)
+ context.instance_variable_set(:@aop_instances, aspect_instances)
end
aspect_instances << self
end
- def aop_add_method_hooks
- return if aop_advices.empty?
+ def add_method_hooks
+ return if advices.empty?
- if @aop_options[:class_methods]
- return unless @aop_target.is_a?(Module)
+ if @options[:class_methods]
+ return unless @target.is_a?(Module)
- eigen_class = class << @aop_target; self; end
- orig_singleton_method_added = @aop_target.method(:singleton_method_added)
+ eigen_class = class << @target; self; end
+ orig_singleton_method_added = @target.method(:singleton_method_added)
eigen_class.send :define_method, :singleton_method_added do |method|
aop_singleton_method_added(method) do
orig_singleton_method_added.call(method)
end
end
else
- eigen_class = class << @aop_target; self; end
+ eigen_class = class << @target; self; end
- if @aop_target.is_a? Module
- orig_method_added = @aop_target.method(:method_added)
+ if @target.is_a? Module
+ orig_method_added = @target.method(:method_added)
else
orig_method_added = eigen_class.method(:method_added)
end
@@ -238,35 +176,35 @@ def aop_add_method_hooks
end
end
- def aop_filter_advices advices, method
+ def filter_advices advices, method
advices.select do |advice|
advice.match?(method, self)
end
end
- def aop_recreate_method method, advices, scope
- @aop_context.instance_variable_set(:@aop_creating_method, true)
+ def recreate_method method, advices, scope
+ context.instance_variable_set(:@aop_creating_method, true)
raw_advices = advices.select {|advice| advice.raw? }
if raw_advices.size > 0
raw_advices.each do |advice|
- if @aop_target.is_a? Module and not @aop_options[:class_methods]
- @aop_target.class_exec method, self, &advice.advice_block
+ if @target.is_a? Module and not @options[:class_methods]
+ @target.class_exec method, self, &advice.advice_block
else
- @aop_target.instance_exec method, self, &advice.advice_block
+ @target.instance_exec method, self, &advice.advice_block
end
end
return if raw_advices.size == advices.size
end
begin
- @aop_wrapped_methods[method] = @aop_context.instance_method(method)
+ @wrapped_methods[method] = context.instance_method(method)
rescue
# ignore undefined method error
- if @aop_options[:old_methods_only]
- aop_logger.log Logging::WARN, 'method-not-found', method
+ if @options[:old_methods_only]
+ logger.log Logging::WARN, 'method-not-found', method
end
return
@@ -278,51 +216,51 @@ def aop_recreate_method method, advices, scope
(around_advices.size - 1).downto(1) do |i|
advice = around_advices[i]
- aop_recreate_method_with_advices method, [], [], advice
+ recreate_method_with_advices method, [], [], advice
end
- aop_recreate_method_with_advices method, before_advices, after_advices, around_advices.first, true
+ recreate_method_with_advices method, before_advices, after_advices, around_advices.first, true
- @aop_context.send scope, method if scope != :public
+ context.send scope, method if scope != :public
ensure
- @aop_context.send :remove_instance_variable, :@aop_creating_method
+ context.send :remove_instance_variable, :@aop_creating_method
end
- def aop_recreate_method_with_advices method, before_advices, after_advices, around_advice, is_outermost = false
+ def recreate_method_with_advices method, before_advices, after_advices, around_advice, is_outermost = false
aspect = self
code = METHOD_TEMPLATE.result(binding)
- aspect.aop_logger.log Logging::DEBUG, 'generate-code', method, code
- @aop_context.class_eval code, __FILE__, __LINE__ + 4
+ aspect.logger.log Logging::DEBUG, 'generate-code', method, code
+ context.class_eval code, __FILE__, __LINE__ + 4
end
METHOD_TEMPLATE = ERB.new <<-CODE, nil, "%<>"
- orig_method = aspect.aop_wrapped_methods['<%= method %>']
+ orig_method = aspect.send :get_wrapped_method_of, '<%= method %>'
% if around_advice
wrapped_method = instance_method(:<%= method %>)
% end
define_method :<%= method %> do |*args, &block|
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'enter-generated-method'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'enter-generated-method'
% end
- if aspect.aop_disabled?
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit--generated-method'
+ if aspect.disabled?
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit--generated-method'
% end
return orig_method.bind(self).call(*args, &block)
end
% if is_outermost
- result = catch(:aop_returns) do
+ result = catch(:returns) do
% end
% before_advices.each do |advice|
# Before advice: <%= advice.name %>
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
% end
% if advice.advice_code
result = (<%= advice.advice_code %>)
@@ -332,13 +270,13 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
if advice.options[:method_arg] %>'<%= method %>', <% end
%>*args
% end
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= advice.name %>'
% end
% if advice.options[:skip_if_false]
unless result
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit-method-due-to-before-filter', '<%= advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit-method-due-to-before-filter', '<%= advice.name %>'
% end
return
end
@@ -347,18 +285,18 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
% if around_advice
# Around advice: <%= around_advice.name %>
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= around_advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= around_advice.name %>'
% end
% if around_advice.advice_code
result = (<%= around_advice.advice_code.gsub('INVOKE_PROXY', 'wrapped_method.bind(self).call(*args, &block)') %>)
% else
-% if aop_logger.visible?(Logging::TRACE)
+% if logger.visible?(Logging::TRACE)
proxy = lambda do |*args, &block|
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-proxy'
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-proxy'
res = wrapped_method.bind(self).call *args, &block
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-proxy'
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-proxy'
res
end
result = <%= around_advice.with_method %> <%
@@ -372,28 +310,28 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
%>wrapped_method.bind(self), *args, &block
% end
% end
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= around_advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= around_advice.name %>'
% end
% else
# Invoke original method
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-wrapped-method'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-wrapped-method'
% end
result = orig_method.bind(self).call *args, &block
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--wrapped-method'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--wrapped-method'
% end
% end
% unless after_advices.empty?
% after_advices.each do |advice|
# After advice: <%= advice.name %>
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
% end
% if advice.advice_code
result = (<%= advice.advice_code %>)
@@ -411,8 +349,8 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
%>*args
% end
% end
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= advice.name %>'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= advice.name %>'
% end
% end
% end
@@ -423,8 +361,8 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
end # end of catch
% end
-% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit--generated-method'
+% if logger.visible?(Logging::TRACE)
+ aspect.logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit--generated-method'
% end
result
end
View
115 lib/aspector/base_class_methods.rb
@@ -3,133 +3,114 @@ class Base
module ClassMethods
::Aspector::Base.extend(self)
- def aop_enable
- aop_logger.log Logging::INFO, 'enable-aspect'
- send :define_method, :aop_disabled? do
+ def enable
+ logger.log Logging::INFO, 'enable-aspect'
+ send :define_method, :disabled? do
end
nil
end
- alias enable aop_enable
- def aop_disable
- aop_logger.log Logging::INFO, 'disable-aspect'
- send :define_method, :aop_disabled? do
+ def disable
+ logger.log Logging::INFO, 'disable-aspect'
+ send :define_method, :disabled? do
true
end
nil
end
- alias disable aop_disable
# if ENV["ASPECTOR_LOGGER"] is set, use it
# else try to load logem and use Logem::Logger
# else use built in logger
- def aop_logger
- @aop_logger ||= Logging.get_logger(self)
+ def logger
+ @logger ||= Logging.get_logger(self)
end
- alias logger aop_logger
- def aop_logger= logger
- @aop_logger = logger
+ def advices
+ @advices ||= []
end
- alias logger= aop_logger=
- def aop_advices
- @aop_advices ||= []
+ def default_options
+ @default_options ||= {}
end
- alias advices aop_advices
- def aop_default_options
- @aop_default_options ||= {}
- end
- alias default_options aop_default_options
-
- def aop_apply target, *rest
+ def 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
+ logger.log Logging::INFO, 'apply', target, options.inspect
aspect_instance = new(target, options)
- aspect_instance.send :aop_apply
+ aspect_instance.send :apply
aspect_instance
end
result.size == 1 ? result.first : result
end
- alias apply aop_apply
+
+ private
- def aop_default options
- if @aop_default_options
- @aop_default_options.merge! options
+ def default options
+ if @default_options
+ @default_options.merge! options
else
- @aop_default_options = options
+ @default_options = options
end
end
- alias default aop_default
- 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
+ def before *methods, &block
+ advices << advice = _create_advice_(Aspector::AdviceMetadata::BEFORE, self, methods, &block)
+ advice.index = advices.size
+ logger.log Logging::INFO, 'define-advice', advice
advice
end
- alias before aop_before
- 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
+ def before_filter *methods, &block
+ advices << advice = _create_advice_(Aspector::AdviceMetadata::BEFORE_FILTER, self, methods, &block)
+ advice.index = advices.size
+ logger.log Logging::INFO, 'define-advice', advice
advice
end
- alias before_filter aop_before_filter
- 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
+ def after *methods, &block
+ advices << advice = _create_advice_(Aspector::AdviceMetadata::AFTER, self, methods, &block)
+ advice.index = advices.size
+ logger.log Logging::INFO, 'define-advice', advice
advice
end
- alias after aop_after
- 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
+ def around *methods, &block
+ advices << advice = _create_advice_(Aspector::AdviceMetadata::AROUND, self, methods, &block)
+ advice.index = advices.size
+ logger.log Logging::INFO, 'define-advice', advice
advice
end
- alias around aop_around
- 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
+ def raw *methods, &block
+ advices << advice = _create_advice_(Aspector::AdviceMetadata::RAW, self, methods, &block)
+ advice.index = advices.size
+ logger.log Logging::INFO, 'define-advice', advice
advice
end
- alias raw aop_raw
- def aop_target code = nil, &block
+ def target code = nil, &block
raise ArgumentError.new('No code or block is passed.') unless code or block_given?
logic = DeferredLogic.new(code || block)
- aop_deferred_logics << logic
+ _deferred_logics_ << logic
logic
end
- alias target aop_target
- def aop_options
+ def options
DeferredOption.new
end
- alias options aop_options
-
- private
- def aop_deferred_logics
- @aop_deferred_logics ||= []
+ def _deferred_logics_
+ @deferred_logics ||= []
end
- def aop_create_advice meta_data, klass_or_module, *methods, &block
+ def _create_advice_ meta_data, klass_or_module, *methods, &block
methods.flatten!
options = meta_data.default_options.clone
@@ -148,7 +129,7 @@ def aop_create_advice meta_data, klass_or_module, *methods, &block
methods[i] = methods[i].to_s if methods[i].is_a? Symbol
end
- methods << aop_options[:method] << aop_options[:methods] if methods.empty?
+ methods << DeferredOption.new(:method) << DeferredOption.new(:methods) if methods.empty?
Aspector::Advice.new(self,
meta_data.advice_type,
View
4 lib/aspector/deferred_option.rb
@@ -2,6 +2,10 @@ module Aspector
class DeferredOption
attr_reader :key
+
+ def initialize key = nil
+ @key = key
+ end
def [] key
@key = key
View
2 lib/aspector/logger.rb
@@ -29,7 +29,7 @@ def visible? level
def log_prefix level
s = "#{Time.now} | Aspector | " << level_to_string(level) << " | "
if context.is_a? Aspector::Base
- s << context.class.to_s << " | " << context.aop_target.to_s << " | "
+ s << context.class.to_s << " | " << context.target.to_s << " | "
else
s << context.to_s << " | "
end
View
10 lib/aspector/method_matcher.rb
@@ -15,20 +15,26 @@ def match? method, aspect = nil
when Symbol
item.to_s == method
when DeferredLogic
- value = aspect.aop_deferred_logic_results(item)
+ value = aspect.deferred_logic_results(item)
if value
new_matcher = MethodMatcher.new(value)
new_matcher.match?(method)
end
when DeferredOption
- value = aspect.send(:aop_options)[item.key]
+ value = aspect.options[item.key]
if value
new_matcher = MethodMatcher.new(value)
new_matcher.match?(method)
end
end
end
end
+
+ def use_deferred_logic? logic
+ @match_data.detect do |item|
+ logic == item
+ end
+ end
def to_s
@match_data.map {|item| item.inspect }.join ", "
View
12 lib/aspector/object_extension.rb
@@ -8,23 +8,23 @@ def aspector *args, &block
aspect = Aspector(options, &block)
- aspect.aop_apply(self) if self.is_a? Module
- args.each {|target| aspect.aop_apply(target) }
+ aspect.apply(self) if self.is_a? Module
+ args.each {|target| aspect.apply(target) }
aspect
end
def Aspector options = {}, &block
klass = Class.new(Aspector::Base)
- klass.aop_default options
+ klass.class_eval { default options }
klass.class_eval &block if block_given?
klass
end
- def aop_returns value = nil
- throw :aop_returns, value
+ def returns value = nil
+ throw :returns, value
end
- alias :returns :aop_returns
+ alias :returns :returns
end
end
View
8 spec/unit/base_class_methods_spec.rb
@@ -6,8 +6,8 @@
before :test, :do_before
end
- klass.send(:aop_advices).size.should == 1
- advice = klass.send(:aop_advices).first
+ klass.send(:advices).size.should == 1
+ advice = klass.send(:advices).first
advice.before?.should be_true
advice.options[:skip_if_false].should_not be_true
advice.with_method.should == :do_before
@@ -18,8 +18,8 @@
before_filter :test, :do_before
end
- klass.send(:aop_advices).size.should == 1
- advice = klass.send(:aop_advices).first
+ klass.send(:advices).size.should == 1
+ advice = klass.send(:advices).first
advice.before?.should be_true
advice.options[:skip_if_false].should be_true
advice.with_method.should == :do_before
View
2 spec/unit/base_spec.rb
@@ -6,7 +6,7 @@
default :test => 'value'
end
- aspect.send(:aop_default_options)[:test].should == 'value'
+ aspect.send(:default_options)[:test].should == 'value'
end
it "#options is used to access options set when aspect is applied" do
View
4 spec/unit/method_matcher_spec.rb
@@ -23,7 +23,7 @@ module Aspector
matcher = MethodMatcher.new(logic)
aspect = mock(Aspector::Base)
- aspect.should_receive(:aop_deferred_logic_results).with(logic).once.and_return(/test/)
+ aspect.should_receive(:deferred_logic_results).with(logic).once.and_return(/test/)
matcher.match?('test', aspect).should_not be_nil
end
@@ -33,7 +33,7 @@ module Aspector
matcher = MethodMatcher.new(option)
aspect = mock(Aspector::Base)
- aspect.should_receive(:aop_options).once.and_return({:methods => /test/})
+ aspect.should_receive(:options).once.and_return({:methods => /test/})
matcher.match?('test', aspect).should_not be_nil
end

0 comments on commit 5674211

Please sign in to comment.
Something went wrong with that request. Please try again.