ruby配置gem嵌套属性不工作 [英] ruby configuration gem nested properties not working
问题描述
我正在为项目使用ruby'configuration'gem。目前,我在我的项目模块中有一个应用程序类,要获取配置,调用 App.config
返回配置对象。
I am using the ruby 'configuration' gem for a project. Currently, I have an app class in my project module, and to get configuration, calling App.config
returns the Configuration object.
在我访问嵌套配置变量的类中,我将调用 App.config.rabbitmq.host
。但是,这不工作,因为rabbitmq返回一个散列。
In my classes to access a nested config variable, I would call App.config.rabbitmq.host
. However, this isn't working because rabbitmq is returning a hash.
base = Configuration.for('default') {
rabbitmq {
host 'localhost'
port 5672
username 'guest'
password 'guest'
vhost '/'
}
}
这就是我的配置。它由我使用的实际配置对象继承:
That is how my configuration looks. It is inherited by the actual configuration object i am using:
Configuration.for('development', base) {
}
我做错了什么?我需要在访问嵌套配置的类中的配置gem。
What am I doing wrong? I required the configuration gem in the classes where I am accessing the nested config.
感谢
推荐答案
请不要误会我,但你做错了是你使用一个宝石这样一个简单的问题。为什么不尝试加载一个简单的哈希?我知道我真的没有回答你的具体问题。但相信我,减少简单问题的外部依赖将会节省你和你的应用程序在未来的小问题。
Please don't get me wrong but what you're doing wrong is that you're using a gem for such a simple problem. Why don't you try to load a simple hash? I know I really didn't answer your specific question. But believe me, reducing external dependencies for simple problems will save you and your app for little problems in the future.
这篇关于ruby配置gem嵌套属性不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!