Search the web
Sign In
New User? Sign Up
rails_artist · Only Ruby on Rails Artist here
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
simple AOP implementation in ruby   Message List  
Reply | Forward Message #13 of 23 |
i was suppose to work on some of my other projects, but i passed my time by
writing a simple aop implementation in ruby.
it is neither powerful like AspectJ nor comparable with AspectR. however, i
was having fun with my day off.

here is how my simple example is running-

def test_aop
# apply pointcuts
apply_advices(:before, /^do_.+/, SimpleService, SimpleServiceAdvice,
:before_do)
apply_advices(:around, /^do_.+/, SimpleService, SimpleServiceAdvice,
:around_do)
apply_advices(:after, /^do_.+/, SimpleService, SimpleServiceAdvice,
:after_do)

simple_service = SimpleService.new
simple_service.do_1("A")
end


here is the parameter name.

apply_advices(type_of_advice, pointcuts_in_regex, service_class,
advice_class, advice_method)

instead of making aspectJ type pointcuts syntax, i have used regex, which is
fine for the time being.

if you run this code you will find the following output -

Before execution.
Around {
1 performed - A
}
After execution.

now let's have a look on my *SimpleService* class.

class SimpleService

def do_1(p_param)
puts "1 performed - #{p_param}"
end

def do_2
puts "2 performed."
end

def no_do
puts "No do"
end
end

and here is my aspect class,

class SimpleServiceAdvice

def around_do(p_invoke)
puts "Around { "
output = p_invoke.proceede()
puts "}"
return output
end

def before_do(p_invoke)
puts "Before execution."
end

def after_do(p_params, p_output)
puts "After execution."
end
end

my implementation is very straight forward, actually during implementing
this stuff, i really felt the strength of meta programming. it is so
flexible and so easy that sky is the limit.

here is the attached source code.
<http://hasan.we4tech.com/wp-content/uploads/2007/11/aop_test.zip>

much better and complete aop implementation in
ruby<http://aspectr.sourceforge.net/>


--
----------------------------------------------------
nhm tanveer hossain khan (hasan)
http://hasan.we4tech.com
----------------------------------------------------
mobile: +880 1713 090 511
----------------------------------------------------
"work for fun"


[Non-text portions of this message have been removed]




Sat Nov 10, 2007 8:47 am

hasan83bd
Offline Offline
Send Email Send Email

Forward
Message #13 of 23 |
Expand Messages Author Sort by Date

i was suppose to work on some of my other projects, but i passed my time by writing a simple aop implementation in ruby. it is neither powerful like AspectJ...
nhm tanveer hossain k...
hasan83bd
Offline Send Email
Nov 10, 2007
8:47 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help