lib/rmobio/config_manager.rb in rmobio-1.1.11 vs lib/rmobio/config_manager.rb in rmobio-1.1.12
- old
+ new
@@ -21,32 +21,34 @@
# 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):
+# (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")
+# 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']
+# MOBIO_CONFIG['ad_network']
#
module Rmobio
module ConfigManager
+ EXTERNAL_CONTEXT_PROP = '_external_context' unless defined? EXTERNAL_CONTEXT_PROP
+
if defined? RAILS_DEFAULT_LOGGER
logger = RAILS_DEFAULT_LOGGER
else
logger = nil
end
@@ -63,54 +65,62 @@
MOBIO_CONFIG = app_yaml_file[RAILS_ENV]
# Replace all properties containing @somekey@ with the value of
# "somekey"
MOBIO_CONFIG.each do |key, value|
+
+ # Run the value filter process
filter_value = value.to_s.strip
filter_key = /@(.*)@/.match(filter_value).to_s.strip
- if not filter_key.nil? and not filter_key == ''
+ if filter_key and filter_key != ''
filter_key = filter_key.gsub(/@/,'')
- if not filter_key.nil? and not filter_value.nil? and not filter_key == ''
+ if filter_key and filter_value and filter_key != ''
filter_value = filter_value.gsub(/@.*@/, MOBIO_CONFIG[filter_key.strip])
- logger.debug('filtered key: ' + key + ' filtered value: ' + filter_value) unless logger.nil?
+ logger.debug('filtered key: ' + key + ' filtered value: ' +
+ filter_value) unless logger.nil?
MOBIO_CONFIG[key] = filter_value
- end
+ end
end
end
else
- raise StandardError, "config/rmobio.yml exists, but doesn't have a configuration for RAILS_ENV=#{RAILS_ENV}."
+ 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."
+ # "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
+ # 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
+ if url
+ if context and context != ''
+ 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
+ else
+ return MOBIO_CONFIG[url].gsub('/' + EXTERNAL_CONTEXT_PROP, '')
+ end
+ end
+ end
end
end
# Now we want to initialize the MOBIO_CONFIG constant
include Rmobio::ConfigManager
\ No newline at end of file