Sha256: fac70ec7722ae2464627457464c88eacf9f2a4a50fd5bd82c291c06183d1e07b
Contents?: true
Size: 1.14 KB
Versions: 28
Compression:
Stored size: 1.14 KB
Contents
require 'yaml' module TaliaUtil module Configuration # This is an object representation of a configuration file, the elements # of the file can be directly accessed using dynamic getters/setters on the # the class. class ConfigFile # Initialize from the given template def initialize(template) @config_doc = YAML::load_file(template) end # Write the configuration to the given file def write(file) open(file, 'w') { |io| io.puts(@config_doc.to_yaml) } end def [](id) @config_doc[id] end # Automatically creates "accessors" for the config properties. def method_missing(method, *params) method = method.to_s assign = method[-1..-1] == '=' # True if last char is a = result = nil if(assign) return super if(params.size != 1) result = @config_doc[method[0..-2]] = params[0] else return super if(params.size != 0) result = @config_doc[method] end result end end end end
Version data entries
28 entries across 28 versions & 1 rubygems