markbates / configatron

A super cool, simple, and feature rich configuration system for Ruby apps.

Home Page:http://www.metabates.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the base setting will be override by hash value

sunteya opened this issue · comments

CODE:

# gem "configatron", "~> 2.8.2"

Settings = Configatron.instance

Settings.remote.ntp = "localhost"
Settings.remote.servers = {
  :ntp => "58.196.13.13"
}

puts Settings.remote.ntp  # print "58.196.13.13"

I would think Settings.remote.ntp should be print localhost
and Settings.remote.servers.ntp should be print 58.196.13.13

This seems like a really strange bug, and wouldn't have happened in app_data. I'll investigate and maybe make a pull request to fix this.

Configatron definitely acts weird with Hashes. I think what is happening is if you assign a hash it automatically sets each key as a configuration setting one level up. For example,

$ configatron.cats = {:foo => :bar, :baz => :bat}
=> {:foo=>:bar, :baz=>:bat}

$ configatron
=> configatron.baz = :bat
configatron.cats = {:foo=>:bar, :baz=>:bat}
configatron.foo = :bar

A workaround is to use configure_from_hash like so:

$ configatron.cats.configure_from_hash(:foo => :bar, :baz => :bat)
=> {:foo=>:bar, :baz=>:bat}
$ configatron
=> configatron.cats.baz = :bat
configatron.cats.foo = :bar

I am guessing there is a check for Hash inside configatron that triggers this odd behavior.