Permalink
Browse files

Change around implementation

  • Loading branch information...
1 parent 8dccc8e commit 827c83ab32cf17d16bba6155bb07fd7e7ec7bfa7 @gcao committed Mar 13, 2012
@@ -14,18 +14,18 @@ def test
aspector(A) do
target do
- def do_this proxy, &block
+ def do_this &proxy
puts 'before'
- proxy.call &block
+ proxy.call
puts 'after'
end
end
around :test, :do_this
- around :test do |proxy, &block|
+ around :test do |&proxy|
puts 'before(block)'
- proxy.call &block
+ proxy.call
puts 'after(block)'
end
end
View
@@ -48,12 +48,12 @@ class CacheAspect < Aspector::Base
def after_initialize
aspect = self
- around options[:method], :method_name_arg => true do |method, proxy, &block|
+ around options[:method], :method_name_arg => true do |method, &proxy|
key = method
ttl = aspect.options[:ttl]
SimpleCache.cache key, ttl do
- proxy.call &block
+ proxy.call
end
end
end
@@ -15,8 +15,8 @@ def test input
class ExceptionHandler < Aspector::Base
target do
- def handle_exception proxy, *args, &block
- proxy.call *args, &block
+ def handle_exception *args, &proxy
+ proxy.call
rescue => e
puts "Rescued: #{e}"
end
@@ -16,10 +16,10 @@ class LoggingAspect < Aspector::Base
ALL_METHODS = /.*/
- around ALL_METHODS, :except => :class, :method_name_arg => true do |method, proxy, *args, &block|
+ around ALL_METHODS, :except => :class, :method_name_arg => true do |method, *args, &proxy|
class_method = "#{self.class}.#{method}"
puts "Entering #{class_method}: #{args.join(',')}"
- result = proxy.call *args, &block
+ result = proxy.call
puts "Exiting #{class_method}: #{result}"
result
end
View
@@ -16,8 +16,8 @@ def test
class RetryAspect < Aspector::Base
target do
- def retry_this proxy, &block
- proxy.call &block
+ def retry_this &proxy
+ proxy.call
rescue => e
@retry_count ||= 3
@retry_count -= 1
View
@@ -26,32 +26,11 @@ def initialize target, options = {}
after_initialize
end
- def aop_enable
- class << self
- def aop_disabled?; end
- end
- end
- alias enable aop_enable
-
- def aop_disable
- class << self
- def aop_disabled?; true; end
- end
- end
- alias disable aop_disable
-
- def aop_reset_disabled
- class << self
- remove_method :aop_disabled?
- end
- end
- alias reset_disabled :aop_reset_disabled
-
def aop_disabled?
end
def disabled?
- aop_disabled
+ aop_disabled?
end
def aop_advices
@@ -310,9 +289,13 @@ def aop_recreate_method_with_advices method, before_advices, after_advices, arou
<% if around_advice %>
# Around advice
<% if around_advice.options[:method_name_arg] %>
- result = <%= around_advice.with_method %> '<%= method %>', wrapped_method.bind(self), *args, &block
+ result = <%= around_advice.with_method %> '<%= method %>', *args do
+ wrapped_method.bind(self).call *args, &block
+ end
<% else %>
- result = <%= around_advice.with_method %> wrapped_method.bind(self), *args, &block
+ result = <%= around_advice.with_method %> *args do
+ wrapped_method.bind(self).call *args, &block
+ end
<% end
else
%>
@@ -4,13 +4,13 @@ module ClassMethods
::Aspector::Base.extend(self)
def aop_enable
- def aop_disabled?
+ send :define_method, :aop_disabled? do
end
end
alias :enable :aop_enable
def aop_disable
- def aop_disabled?
+ send :define_method, :aop_disabled? do
true
end
end
@@ -17,9 +17,9 @@ def test input
require 'aspector'
class AroundAspect < Aspector::Base
- around :test do |proxy, *args, &block|
+ around :test do |*args, &proxy|
begin
- proxy.call *args, &block
+ proxy.call
rescue => e
end
end
@@ -13,8 +13,8 @@ def test_no_aspect; end
def test; end
- def around_test proxy, &block
- proxy.call &block
+ def around_test &proxy
+ proxy.call
end
end
@@ -22,9 +22,9 @@ def test
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after"
result
end
@@ -51,9 +51,9 @@ def value
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after"
result
end
@@ -12,9 +12,9 @@
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after"
result
end
@@ -39,9 +39,9 @@ def after_initialize
result
end
- around(:test) do |proxy, &block|
+ around(:test) do |&proxy|
value << "do_around_before(#{name})"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after(#{name})"
result
end
@@ -12,9 +12,9 @@
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after"
result
end
@@ -28,9 +28,9 @@
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before2"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after2"
result
end
@@ -12,9 +12,9 @@
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after"
result
end
@@ -26,9 +26,9 @@
result
end
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "do_around_before2"
- result = proxy.call &block
+ result = proxy.call
value << "do_around_after2"
result
end
View
@@ -3,9 +3,9 @@
describe "Around advices" do
it "should work" do
klass = create_test_class do
- def do_this proxy, &block
+ def do_this &proxy
value << "before"
- result = proxy.call &block
+ result = proxy.call
value << "after"
result
end
@@ -24,9 +24,9 @@ def do_this proxy, &block
klass = create_test_class
aspector(klass) do
- around :test do |proxy, &block|
+ around :test do |&proxy|
value << "before"
- result = proxy.call &block
+ result = proxy.call
value << "after"
result
end
@@ -39,9 +39,9 @@ def do_this proxy, &block
it "method_name_arg" do
klass = create_test_class do
- def do_this method, proxy, &block
+ def do_this method, &proxy
value << "before(#{method})"
- result = proxy.call &block
+ result = proxy.call
value << "after(#{method})"
result
end

0 comments on commit 827c83a

Please sign in to comment.