开发者

Ruby YML file in Adhearsion - where should I load the file?

开发者 https://www.devze.com 2023-04-02 08:28 出处:网络
This code all exists in inbound_did context in dialplan.rb host_config = YAML::load(File.open(\"config/hosts.yml\")).to_hash

This code all exists in inbound_did context in dialplan.rb

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

I'm trying to figure out if I should pu开发者_运维知识库t YAML::load in dialplan.rb or somewhere else. I'd like to only load it once when adhearsion is started but I don't know how I could then access that config variable from the dialplan's scope...


if you want to loads it only one then maybe constant will be OK for you?

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

then if you want to use it in another class then you can do something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消