Sha256: 3f40562dc4d5937ab87eca372bb7ef64fb798f291cc582f956f6de11fb99e773

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'confuse/config_mixin'
require 'confuse/dsl'

module Confuse
  # The default module used for configuration.
  module Config
    extend ConfigMixin
  end

  # Super class for configuration in order to have multiple instances.
  class ConfigBase
    include ConfigMixin
    extend DSL

    def namespaces
      @namespaces ||= {}
    end

    def initialize(options = {})
      load_namespaces(self.class.namespaces.clone)
      paths = options[:paths] || []
      if paths.flatten.empty?
        read_files(self.class.config_path.flatten)
      else
        read_files(paths.flatten)
      end
      options[:conf].tap { |conf| conf && mixin_config!(conf) }
    end

    def config
      self
    end

    def self.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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confuse-0.1.8 lib/confuse/config.rb
confuse-0.1.7 lib/confuse/config.rb