Sha256: 00cf59ca7f8078007923a3749e8df8ab50c6b9e58d348bcf9d9f9149e6ed1203

Contents?: true

Size: 1.12 KB

Versions: 16

Compression:

Stored size: 1.12 KB

Contents

module Merb
  module Global
    @@config = nil
    # call-seq:
    #    config(key)                        => value
    #    config([key1, key2, ...])          => value
    #    config(key, default)               => value
    #    config([key1, key2, ...], default) => value
    #
    # Lookup the configuration
    # ==== Params
    # key<Symbol>:: A key
    # keys<Array[Symbol]>:: Keys
    # default<Object>:: A default value
    #
    # ==== Returns
    # value<Object>:: Object read from configuration or default
    #
    # ==== Examples
    # <tt>Merb::Global.config [:gettext, :domain], 'merbapp'</tt>
    def self.config(keys, default = nil)
      keys = [keys] unless keys.is_a? Array
      #if @@config.nil?
        @@config = Merb::Plugins.config[:merb_global].dup
        unless Merb::Plugins.config[:merb_global][Merb.env].nil?
          @@config.merge! Merb::Plugins.config[:merb_global][Merb.env]
        end
      #end
      current = @@config
      while current.respond_to?(:[]) and not keys.empty?
        current = current[keys.shift]
      end
      (keys.empty? and not current.nil?) ? current : default
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
lastobelus-merb_global-0.0.10 lib/merb_global/config.rb
lastobelus-merb_global-0.0.11 lib/merb_global/config.rb
lastobelus-merb_global-0.0.12 lib/merb_global/config.rb
lastobelus-merb_global-0.0.13 lib/merb_global/config.rb
lastobelus-merb_global-0.0.14 lib/merb_global/config.rb
lastobelus-merb_global-0.0.8 lib/merb_global/config.rb
lastobelus-merb_global-0.0.9 lib/merb_global/config.rb
emipair-merb_global-0.0.12 lib/merb_global/config.rb
emipair-merb_global-0.0.11 lib/merb_global/config.rb
emipair-merb_global-0.0.10 lib/merb_global/config.rb
emipair-merb_global-0.0.9 lib/merb_global/config.rb
emipair-merb_global-0.0.3 lib/merb_global/config.rb
emipair-merb_global-0.0.2 lib/merb_global/config.rb
emipair-merb_global-0.0.1 lib/merb_global/config.rb
merb_global-0.0.7 lib/merb_global/config.rb
merb_global-0.0.6 lib/merb_global/config.rb