Skip to content

Instantly share code, notes, and snippets.

View gcao's full-sized avatar

Guoliang Cao gcao

  • Apex, NC
  • 06:53 (UTC -04:00)
  • X @gcao99
View GitHub Profile
around :test do |proxy|
puts 'around 1 (before)'
result = a4r_invoke proxy
puts 'around 1 (after)'
result
end
before :test do
puts 'before'
end
before :test do
puts 'before 1'
end
a4r_group do
before :test do
puts 'before 2'
end
end
before :test do
puts 'before 1'
end
around :test do |proxy|
puts 'around(before)'
result = a4r_invoke proxy
puts 'around(after)'
result
end
it "around advice" do
advice = Klass.a4r_data[:test][0]
advice.around?.should be_true
o = Klass.new
o.expects(:a4r_invoke).with(:proxy, 1)
advice.invoke(o, :proxy, 1)
o.value.should == %w(around(before) around(after))
class A
class << self
include Aspect4r
before :test do |input|
puts 'before test'
end
after :test do |result, input|
puts 'after test'
class A
include Aspect4r::Classic
a4r_around :test do |proxy, value|
end
a4r_before_filter :test do |value|
end
a4r_before :test do |value|
class A
include Aspect4r
before :test, :method_name_arg => true do |method, value|
puts "Entering #{method}(#{value.inspect})"
end
after :test, :method_name_arg => true do |method, result, value|
puts "Exiting from #{method} with result #{result.inspect}."
result
class A
include Aspect4r
before :test, :validate
after :test, :handle_result
def test value
value
end
class A
include Aspect4r
def test value
puts 'test'
value
end
around :test do |proxy, value|
puts 'around 1'