2012-11-06 50 views
0

我正在使用thrift_client 0.8.1 library。它支持一些鉤子接口。如何使用thrift_client庫掛鉤功能?

client = ThriftClient.new(FooService, host) 

client.add_callback :before_method do |*args| 
    ActionController::Base.logger.info instance_eval("@current_server") 
    logger.info args.inspect 
end 

client.add_callback :post_connect do |client| 
    logger.info "A thrift server connection has been made<#{client.current_server}>" 
end 

每次調用一個方法,我想寫日誌節儉服務器的信息。 所以我安裝了:before method鉤子,但我認爲instance_eval("@current_server")不能按我的預期工作。 @current_serverThriftClient類中的一個實例變量。問題是什麼?

回答

0

我不相信:before_method回調是在ThriftClient實例上下文中調用的。這是調用:before_method:

def do_callbacks(callback_type_sym, *args) 
    return unless @callbacks[callback_type_sym] 
    @callbacks[callback_type_sym].each do |callback| 
     callback.call(*args) 
    end 
    end 

:before_method CB用方法名調用。對於:post_connect它是客戶端實例。