3 class GMapsAPIKeyConfigFileNotFoundException < StandardError
\r
6 class AmbiguousGMapsAPIKeyException < StandardError
\r
9 #Class fo the manipulation of the API key
\r
11 #Read the API key config for the current ENV
\r
12 unless File.exist?(RAILS_ROOT + '/config/gmaps_api_key.yml')
\r
13 raise GMapsAPIKeyConfigFileNotFoundException.new("File RAILS_ROOT/config/gmaps_api_key.yml not found")
\r
15 env = ENV['RAILS_ENV'] || RAILS_ENV
\r
16 GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[env]
\r
19 def self.get(options = {})
\r
20 if options.has_key?(:key)
\r
22 elsif GMAPS_API_KEY.is_a?(Hash)
\r
23 #For this environment, multiple hosts are possible.
\r
24 #:host must have been passed as option
\r
25 if options.has_key?(:host)
\r
26 GMAPS_API_KEY[options[:host]]
\r
28 raise AmbiguousGMapsAPIKeyException.new(GMAPS_API_KEY.keys.join(","))
\r
31 #Only one possible key: take it and ignore the :host option if it is there
\r