簡易なruby AOPフレームワークです.


smart memcacheを開発する過程で,簡易ruby aopを開発した.
before,after,rescueのブロックをサポートし,繰り返し,任意の組合せのブロック宣言をサポートする.
arround interceptor宣言は、後続バージョンでサポートされています.
基本的な使用コードは次のとおりです.
afterブロッキング使用:

@ruby_aop = AOP::RubyAop.new 
@ruby_aop.interceptor(:classes=>["User","Teacher"],:methods=>[:update_all],:interceptor_type=>:after) { |aop_info,*args| # your after block here }

説明:
aop_infoはaopのメタデータで、タイプはhashです.プライマリ・メタデータ:

 @aop_inf[:intercepted_class]        (quanlified class name)
 @aop_inf[:intercepted_method]         (symbol)
 @aop_inf[:intercepted_method_is_class_method]      ) (true|false)

*argsは、ブロックされたメソッドによって呼び出されるパラメータです.
beforeブロック使用:
@ruby_aop = AOP::RubyAop.new 
@ruby_aop.interceptor(:classes=>["User","Teacher"],:methods=>[:update_all],:interceptor_type=>:before) { |aop_info,*args| # your after block here }

:interceptor_type=>:beforeをafterからbeforeに変更
rescue同様::interceptor_type=>:rescue
rescueではaopinfoで:errorで異常情報を取得できます.
次のバージョンではarround interceptorのサポートが行われます.使用例は次の通りです.
arround_statement_str=<<END
   #hahahah before statement here
   AOP_ORIGINAL_METHOD_CALL
   ##bla bla after statement here 
   
END
@ruby_aop = AOP::RubyAop.new 
@ruby_aop.interceptor(:classes=>["User","Teacher"],:methods=>[:update_all],:interceptor_type=>:arround,:arround_body=>arround_statement_str) 


ここでarround_statement_strの元のメソッドの呼び出しには、特殊なフラグ列を使用する必要があります.
AOP_ORIGINAL_METHOD_CALL