Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Can give advice a custom name

  • Loading branch information...
commit 02535eb00903c72d89eaacbd93b04a64c148aa39 1 parent 65ba532
@gcao authored
View
2  examples/activerecord_hooks.rb
@@ -13,7 +13,7 @@ def save
require 'aspector'
class ActiveRecordHooks < Aspector::Base
- logger.level = Aspector::Logger::TRACE
+ logger.level = Aspector::Logging::TRACE
default :private_methods => true
View
2  examples/cache_aspect.rb
@@ -46,7 +46,7 @@ def self.cache key, ttl
class CacheAspect < Aspector::Base
default :ttl => 60
- around :aspect_arg => true, :method_arg => true do |aspect, method, proxy, &block|
+ around :name => 'cache', :aspect_arg => true, :method_arg => true do |aspect, method, proxy, &block|
key = method
ttl = aspect.options[:ttl]
View
6 lib/aspector/advice.rb
@@ -18,6 +18,10 @@ def initialize parent, type, method_matcher, with_method, options = {}, &block
@advice_block = block
end
+ def name
+ @options[:name] || "advice #{index}"
+ end
+
def with_method
@with_method ||= "aop_#{hash.abs}"
end
@@ -64,7 +68,7 @@ def type_name
end
def to_s
- s = "<advice " << index.to_s << ">: "
+ s = "#{name}: "
s << type_name
s << " [" << @method_matcher.to_s << "] DO "
if @with_method
View
14 lib/aspector/base.rb
@@ -317,19 +317,19 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
% end
% before_advices.each do |advice|
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<advice <%= advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
% end
result = <%= advice.with_method %> <%
if advice.options[:aspect_arg] %>aspect, <% end %><%
if advice.options[:method_arg] %>'<%= method %>', <% end
%>*args
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<advice <%= advice.index %>>'
+ aspect.aop_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 <%= advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'exit-method-due-to-before-filter', '<%= advice.name %>'
% end
return
end
@@ -339,7 +339,7 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
% if around_advice
# Around advice
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<advice <%= around_advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= around_advice.name %>'
% end
% if aop_logger.visible?(Logging::TRACE)
proxy = lambda do |*args, &block|
@@ -359,7 +359,7 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
%>wrapped_method.bind(self), *args, &block
% end
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<advice <%= around_advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= around_advice.name %>'
% end
% else
@@ -379,7 +379,7 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
# After advices
% after_advices.each do |advice|
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<advice <%= advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'before-invoke-advice', '<%= advice.name %>'
% end
% if advice.options[:result_arg]
result = <%= advice.with_method %> <%
@@ -394,7 +394,7 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
%>*args
% end
% if aop_logger.visible?(Logging::TRACE)
- aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<advice <%= advice.index %>>'
+ aspect.aop_logger.log <%= Logging::TRACE %>, '<%= method %>', 'after--invoke-advice', '<%= advice.name %>'
% end
% end
% end

0 comments on commit 02535eb

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