# # Copyright (C) 2007 Mobio Networks, Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # =begin This module manages yaml-based configuration sets. Uses some logic from the rfacebook gem. =end module Rmobio module ConfigManager if defined? RAILS_DEFAULT_LOGGER logger = RAILS_DEFAULT_LOGGER else logger = nil end begin app_yaml_file = YAML.load_file("#{RAILS_ROOT}/config/rmobio.yml") rescue Exception => e raise StandardError, "config/rmobio.yml could not be loaded." end if app_yaml_file if app_yaml_file[RAILS_ENV] MOBIO_CONFIG = app_yaml_file[RAILS_ENV] # Replace all properties containing @somekey@ with the value of # "somekey" MOBIO_CONFIG.each do |key, value| filter_value = value.to_s.strip filter_key = /@(.*)@/.match(filter_value).to_s.strip if not filter_key.nil? and not filter_key == '' filter_key = filter_key.gsub(/@/,'') if not filter_key.nil? and not filter_value.nil? and not filter_key == '' filter_value = filter_value.gsub(/@.*@/, MOBIO_CONFIG[filter_key.strip]) logger.debug('filtered key: ' + key + ' filtered value: ' + filter_value) unless logger.nil? MOBIO_CONFIG[key] = filter_value end end end else raise StandardError, "config/rmobio.yml exists, but doesn't have a configuration for RAILS_ENV=#{RAILS_ENV}." end else raise StandardError, "config/rmobio.yml does not exist." end end end # Now we want to initialize the MOBIO_CONFIG constant include Rmobio::ConfigManager