class Webgen::Configuration

Stores the configuration for a webgen website.

Configuration options can be created by using the define_option method:

config.define_option "my.new.option", 'default value'

and later accessed or set using the accessor methods [] and []=. A validation block can also be specified when defining an option. This validation block is called when a new value should be set and it should return the (possibly changed) value to be set:

config.define_option "my.new.option", 'default value' do |val|
  raise "Option must be a string" unless val.kind_of?(String)
  val.upcase
end

*Note*: When a Configuration object is dumped (via Marshal), the option validator procs are not dumped and can therefore not be restored!

Attributes

options[R]

Contains all the defined configuration options.

Public Class Methods

new()

Create a new Configuration object.

Public Instance Methods

[](name)

Return the value for the configuration option name.

[]=(name, value)

Use value as value for the configuration option name.

define_option(name, default, &validator)

Define a new option name with a default value of default.

If a validation block is provided, it is called with the new value when one is set and should return a (possibly altered) value to be set.

load_from_file(filename)

Load the configuration values.

If filename is a String, it is treated as the name of the configuration file from which the values should be loaded. If filename responds to #read, it is treated as an IO object from which the values should be loaded.

The configuration needs to be in YAML format. More specifically, it needs to contain a YAML hash which is further processed by set_values.

Returns an array with all unknown configuration options.

option?(name)

Return true if the given option exists.

set_values(values)

Set the configuration values from the Hash values.

The hash can either contain full configuration option names or namespaced option names, ie. in YAML format:

my.option: value

website:
  lang: en
  url: my_url

The above hash will set the option 'my.option' to value, 'website.lang' to en and 'website.url' to my_url.

Returns an array with all unknown configuration options.