Sha256: 2d39d0d5829808c5359724b25b9e7a16b5452225a6149c86eb64dbd649dd69d9
Contents?: true
Size: 1.53 KB
Versions: 7
Compression:
Stored size: 1.53 KB
Contents
module HasGlobalSession module Configuration def self.environment; @environment; end def self.environment=(value); @environment = value; end def self.config_file; @config_file; end def self.config_file=(value); @config_file= value; end def self.[](key) get(key, true) end def self.validate ['attributes/signed', 'integrated', 'cookie/name', 'cookie/domain', 'timeout'].each do |path| elements = path.split '/' object = get(elements.shift, false) elements.each do |element| object = object[element] if object if object.nil? msg = "#{File.basename(config_file)} does not specify required element #{elements.map { |x| "['#{x}']"}.join('')}" raise MissingConfiguration, msg end end end end private def self.get(key, validated) unless @config raise MissingConfiguration, "config_file is nil; cannot read configuration" unless config_file raise MissingConfiguration, "environment is nil; must be specified" unless environment @config = YAML.load(File.read(config_file)) raise TypeError, "#{config_file} must contain a Hash!" unless Hash === @config validate if validated end if @config.has_key?(environment) && @config[environment].has_key?(key) return @config[environment][key] else @config['common'][key] end rescue NoMethodError raise MissingConfiguration, "Configuration key '#{key}' not found" end end end
Version data entries
7 entries across 7 versions & 1 rubygems