Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

using yaml loader for options config

  • Loading branch information...
commit fe5c8d845c10b88bcfbeadb8a3613b256412b2d4 1 parent 6d8780f
@kristianmandrup authored
View
47 lib/gmaps4rails/config.rb
@@ -0,0 +1,47 @@
+require 'singleton'
+
+module Gmaps4rails
+ def self.config
+ Config.instance
+ end
+
+ class Config
+ include Singleton
+
+ def options
+ yaml_loader.load
+ end
+
+ protected
+
+ def yaml_loader
+ @yaml_loader ||= YamlLoader.new
+ end
+
+ class YamlLoader
+ attr_writer :config_file, :config_path
+
+ def load
+ @load ||= HashWithIndifferentAccess.new load_yaml
+ end
+
+ def config_path
+ Rails.root.join 'config', config_file
+ end
+
+ def config_file
+ @config_file ||= 'gmaps4rails.yml'
+ end
+
+ protected
+
+ def load_yaml
+ @yaml ||= begin
+ YAML.load File.read(config_path)
+ rescue
+ {}
+ end
+ end
+ end
+ end
+end
View
2  lib/gmaps4rails/helper/gmaps4rails_helper.rb
@@ -13,6 +13,8 @@ def gmaps4rails(builder)
# full helper to pass all variables and their options
# @params [Hash] options is a Hash containing data and options. Example: { markers:{ data: @json, options: { do_clustering: true } } }
def gmaps(options = {})
+ options = Gmaps4rails.config.load.merge(options)
+
gmaps_libs(options) if options[:with_libs]
options_with_indifferent_access = options.with_indifferent_access
Please sign in to comment.
Something went wrong with that request. Please try again.