2011-09-01 50 views
0

此代碼全部存在於inbound_did背景下dialplan.rbAdhearsion中的Ruby YML文件 - 我應該在哪裏加載文件?

host_config = YAML::load(File.open("config/hosts.yml")).to_hash 
sip_hash = host_config["sip_hash"] 
hostnames = host_config["hostnames"] 

我試圖找出如果我應該把YAML ::負荷dialplan.rb或其他地方。我想只加載一次,當adhearsion開始,但我不知道我怎麼可以然後從dialplan的範圍訪問該配置變量...

回答

2

如果你想加載它只有一個,然後可能會不斷會對你好嗎?

class Dialplan 
    HOST_CONFIG = YAML::load(File.open("config/hosts.yml")).to_hash 

    def some_method 
    sip_hash = HOST_CONFIG["sip_hash"] 
    hostnames = HOST_CONFIG["hostnames"] 
    end 
end 

然後如果你想在其他類中使用它,那麼你可以做這樣的事情:

class Other 
    def other_method 
    sip_hash = Dialplan::HOST_CONFIG["sip_hash"] 
    hostnames = Dialplan::HOST_CONFIG["hostnames"] 
    end 
end 
+0

感謝,這正是我一直在尋找。 –

相關問題