Sha256: d2e1f1839fcdafc1824c611751358579630a068f7c869c5be680a6484a78bf79
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
module Configatron # Used to store each of the 'sets' of configuration parameters. class Store include Configatron::Helpers # The actual key/pair parameter values. attr_reader :parameters # Takes an optional Hash to configure parameters. def initialize(parameters = {}) @parameters = parameters end # If a method is called with an = at the end, then that method name, minus # the equal sign is added to the parameter list as a key, and it's *args # become the value for that key. Eventually the keys become method names. # If a method is called without an = sign at the end then the value from # the parameters hash is returned, if it exists. def method_missing(sym, *args) if sym.to_s.match(/(.+)=$/) @parameters[sym.to_s.gsub("=", '').to_sym] = *args else val = @parameters[sym] return val unless val.nil? return handle_missing_parameter(sym) end end def exists?(name) return true unless @parameters[name.to_sym].nil? super(name) end # Used to create 'namespaces' around a set of configuration parameters. def namespace(name) if exists?(name) yield self.send(name.to_sym) elsif configatron.exists?(name) yield configatron.send(name.to_sym) else ns = Configatron::Store.new yield ns @parameters[name.to_sym] = ns end end end # Store end # Configatron
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
configatron-1.0.0 | lib/store.rb |