ruby configuration gem nested properties not worki

2019-09-08 17:26发布

问题:

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.

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) {
}

What am I doing wrong? I required the configuration gem in the classes where I am accessing the nested config.

Thanks

回答1:

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.