diff --git a/lib/settingslogic.rb b/lib/settingslogic.rb index a99acaf..55c25ac 100644 --- a/lib/settingslogic.rb +++ b/lib/settingslogic.rb @@ -10,7 +10,7 @@ class << self def name # :nodoc: self.superclass != Hash && instance.key?("name") ? instance.name : super end - + # Enables Settings.get('nested.key.name') for dynamic access def get(key) parts = key.split('.') @@ -83,16 +83,15 @@ def create_accessor_for(key) # Initializes a new settings object. You can initialize an object in any of the following ways: # - # Settings.new(:application) # will look for config/application.yml # Settings.new("application.yaml") # will look for application.yaml # Settings.new("/var/configs/application.yml") # will look for /var/configs/application.yml + # Settings.new("http://example.com/configs/application.yml") # will look for http://example.com/configs/application.yml through http # Settings.new(:config1 => 1, :config2 => 2) # # Basically if you pass a symbol it will look for that file in the configs directory of your rails app, # if you are using this in rails. If you pass a string it should be an absolute path to your settings file. # Then you can pass a hash, and it just allows you to access the hash via methods. def initialize(hash_or_file = self.class.source, section = nil) - #puts "new! #{hash_or_file}" case hash_or_file when nil raise Errno::ENOENT, "No file specified as Settingslogic source" @@ -167,22 +166,16 @@ def #{key} end EndEval end - + def symbolize_keys - inject({}) do |memo, tuple| - k = (tuple.first.to_sym rescue tuple.first) || tuple.first - v = k.is_a?(Symbol) ? send(k) : tuple.last # make sure the value is accessed the same way Settings.foo.bar works - memo[k] = v && v.respond_to?(:symbolize_keys) ? v.symbolize_keys : v #recurse for nested hashes - memo end - end - + def missing_key(msg) return nil if self.class.suppress_errors