lib/confuse/config_mixin.rb in confuse-0.1.4 vs lib/confuse/config_mixin.rb in confuse-0.1.5

- old
+ new

@@ -34,12 +34,12 @@ return ns unless rest_of_key ns[rest_of_key, self] end def []=(key, value) - puts "WARNING: changing config after it has been set!" - mixin_config!({key => value}) + puts 'WARNING: changing config after it has been set!' + mixin_config!({ key => value }) end def to_hash namespaces.reduce({}) do |memo, (name, namespace)| namespace.keys.each do |key| @@ -47,10 +47,23 @@ end memo end end + def params_hash + namespaces.reduce({}) do |memo, (name, namespace)| + namespace.keys.each do |key| + item = namespace.get_item(key) + memo[:"#{name}_#{key}"] = { + :type => item.type, + :doc => item.description, + :default => item.default_value } + end + memo + end + end + # We allow the namespace and the key to be concatenated with an '_', so this # method is to search the possible substrings that could make up the # namespace for a key. # # This does not guarentee that the suffix of the namespace that is found is @@ -96,12 +109,10 @@ namespace_name = find_namespace(key) || :default namespace = @namespaces[namespace_name] if value.respond_to?(:keys) # if its a hash, set each key in the hash as a config item in the # namespace - value.each do |k, v| - namespace[k] = v - end + value.each { |k, v| namespace[k] = v } else # otherwise, set it directly in the namespace namespace[rest_of_key(key, namespace_name)] = value end end