nconf.js like gem for ruby configuration

164 views Asked by At

I'm building a cli tool in ruby, and I need to take config from different sources: environment variable, dotfile, arguments or hardcoded values. (with a precedence system)

In node.js I would have used nconf.js, to do this.

Is there some configuration gem in ruby that enable to do such a thing?

1

There are 1 answers

0
airtonix On

The actual answer is this:

updated: 2020-02-26

https://github.com/infochimps-labs/configliere

to quote the author:

Be willing to sit down with the Five Families. Takes settings from (at your option):

  • Pre-defined defaults from constants
  • Simple config files
  • Environment variables
  • Commandline options and git-style command runners
  • Ruby block (called when all other options are in place)

put simply. just like nconf.

require 'configliere'

Settings.use :commandline
Settings({
    :dest_time => '11-05-1955',
    :fluxcapacitor => {
        :speed => 88,
    },
    :delorean => {
        :power_source => 'plutonium',
        :roads_needed => true,
    },
    :username => 'marty',
    :password => '',
})

#set a value to possibly also come from env
Settings.define :dest_time,   :env_var => 'DEST_TIME'

Settings.read "#{__dir__}/config.yml"
Settings.read "#{Dir.pwd()}/config.yml"
Settings.resolve!

old answer:

https://github.com/rubyconfig/config#working-with-environment-variables

it doesn't do argv, but it lets you layer various yaml files and then override with ENV just like nconf lets you.