Parent

Included Modules

Picombo::Config

Config Class

Handles retreiving of key value storage items

Picombo uses config items internally to keep track of common or long term configuration values. These settings are stored in yaml files.

Overview

There are several built in config file types:

 * config.yaml
 * cache.yaml
 * log.yaml
 * mimes.yaml

The only file required to be in your application directory is config.yaml. The rest of the files are defined in the system location. You can change/overwrite the system values by creating the file in your application directory and specifying your application values there. Please refer to the source system files for examples.

Usage

To call config values, use the Picombo::Config.get method. The first parameter is the path of your config value, using dot notation. With dot notation, the first part is the filename, and everything after that is the path inside the file.

Example

For the following file (config.yaml):

 site_domain: localhost:3000
 protocol: http
 extensions:
   []
 hooks:
   [profiler]

You can get the core config values like:

Picombo::Config.get(‘core.protocol’)

Public Class Methods

clear(group) click to toggle source

Clears the internal cache for a config file(s)

    # File lib/classes/config.rb, line 82
82:         def self.clear(group)
83:             @@cache.delete(group)
84:         end
each(file) click to toggle source

Define an each method, required for Enumerable.

     # File lib/classes/config.rb, line 112
112:         def self.each(file)
113: 
114:         end
get(key, required = true) click to toggle source

Retrieves a config item in dot notation

    # File lib/classes/config.rb, line 69
69:         def self.get(key, required = true)
70:             # get the group name from the key
71:             key = key.split('.')
72:             group = key.shift
73: 
74:             value = key_string(load(group), key.join('.'))
75: 
76:             raise "Config key '"+key.join('.')+"' not found!!" if required && value.nil?
77: 
78:             value
79:         end
key_string(hash, keys) click to toggle source

Allows searching an hash by dot seperated strings

     # File lib/classes/config.rb, line 87
 87:         def self.key_string(hash, keys)
 88:             return false if ! hash.is_a? Hash
 89: 
 90:             keys = keys.split('.')
 91: 
 92:             until keys.length == 0
 93:                 key = keys.shift
 94: 
 95:                 if hash.has_key? key
 96:                     if hash[key].is_a? Hash and ! keys.empty?
 97:                         hash = hash[key]
 98:                     else
 99:                         return hash[key]
100:                     end
101:                 else
102:                     break
103:                 end
104:             end
105: 
106:             nil
107:         end
load(name) click to toggle source

Loads configuration files by name

    # File lib/classes/config.rb, line 44
44:         def self.load(name)
45:             # Look for this config item in the cache
46:             if @@cache.has_key?(name)
47:                 return @@cache[name]
48:             end
49: 
50:             configuration, files = {}, Picombo::Core.find_file('config', name, false, 'yaml')
51: 
52:             files.each do |file|
53:                 configuration.merge! YAML::load_file(file)
54:             end
55: 
56:             # Set the internal cache
57:             @@cache[name] = configuration
58: 
59:             configuration
60:             rescue Errno::ENOENT => e
61:             # A config file couldn't be loaded...
62:         end
set(key, value) click to toggle source

Used for dynamic config setting. Not implimented yet

    # File lib/classes/config.rb, line 65
65:         def self.set(key, value)
66:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.