Sha256: 50eea39d97c3d08c929e021b3b3efd960cf240d17bf73b6594643905e5d439bd

Contents?: true

Size: 585 Bytes

Versions: 2

Compression:

Stored size: 585 Bytes

Contents

# coding: utf-8

module Confuse
  # A {Namespace} is a container to keep configuration data seperate from the
  # rest of the config.
  class Namespace
    attr_reader :items

    def initialize(name, &block)
      @name = name
      @items = {}
      block.call(self) if block_given?
    end

    def add_item(name, opts = {})
      @items[name] = Item.new(name, opts)
    end

    def [](key)
      @items[key]
    end

    def to_hash
      @items.reduce({}) do |a, (k,v)|
        key = @name ? :"#{@name}_#{k}" : k
        a.merge({ key => v.to_hash })
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confuse-1.1.1 lib/confuse/namespace.rb
confuse-1.1.0 lib/confuse/namespace.rb