lib/rmobio/config_manager.rb in rmobio-1.1.10 vs lib/rmobio/config_manager.rb in rmobio-1.1.11
- old
+ new
@@ -1,28 +1,52 @@
-#
+#
# 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 <http://www.gnu.org/licenses/>.
-#
-
-=begin
-This module manages yaml-based configuration sets. Uses some logic from the
-rfacebook gem.
-=end
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+#
+# This module manages yaml-based configuration sets. Uses some logic from the
+# rfacebook gem.
+#
+# The config_manager is a yaml-based property management system which follows
+# the same methodology for managing property sets as database.yml. To use the
+# config_manager, perform the following steps:
+#
+# 1. In environment.rb, add the following two lines to the bottom of the file
+# (we want to load the configuration statically):
+#
+# <pre>require 'rmobio/config_manager'</pre>
+#
+# 2. Run the following rake task to generate the boilerplate configs:
+#
+# <pre>rake rmobio:setup</pre>
+#
+# 3. Edit config/rmobio.yml and add your properties (here we set a property
+# called "ad_network" with a value of "ad_sense")
+#
+# <pre>
+# development:
+# ad_network: ad_sense
+# </pre>
+#
+# 4. To use a property, reference the hash accordingly. e.g. @adnetwork =
+# MOBIO_CONFIG['ad_network']
+#
module Rmobio
module ConfigManager
+
if defined? RAILS_DEFAULT_LOGGER
logger = RAILS_DEFAULT_LOGGER
else
logger = nil
end
@@ -32,10 +56,12 @@
raise StandardError, "config/rmobio.yml could not be loaded."
end
if app_yaml_file
if app_yaml_file[RAILS_ENV]
+
+ remove_const :MOBIO_CONFIG if defined? MOBIO_CONFIG
MOBIO_CONFIG = app_yaml_file[RAILS_ENV]
# Replace all properties containing @somekey@ with the value of
# "somekey"
MOBIO_CONFIG.each do |key, value|
@@ -54,10 +80,37 @@
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
+
+ # get_request_context This method checks for the existence of a
+ # "mobio-context" header. If the header exists, then the method returns
+ # the filtered value for the MOBIO_CONFIG array with the key "url."
+ #
+ # Below is the flow:
+ #
+ # A request is made to the server which contains a mobio-context header with
+ # a value of "mycustomcontext" to "/news"
+ #
+ # Calling get_request_context(some_url_property) would return
+ #
+ # "/mycustomcontext/news"
+ #
+ # If no header exists, the method returns the value of the property, unfiltered
+ #
+ def get_external_context(url=nil)
+ external_context_prop = "_external_context"
+
+ context = request.env['HTTP_MOBIO_CONTEXT']
+
+ if context and not context == '' and url
+ external_context = MOBIO_CONFIG[url].gsub(external_context_prop, context)
+ RAILS_DEFAULT_LOGGER.debug 'Utils: Setting the uri to: "' +
+ external_context + '" for the current request.' unless not defined? RAILS_DEFAULT_LOGGER
+ return external_context
+ end
+ end
end
end
-
# Now we want to initialize the MOBIO_CONFIG constant
include Rmobio::ConfigManager
\ No newline at end of file