Commit 3cc435ff2350fc7dc8a8a9a16b32005575914d29

Authored by Matjaz Gregoric
Committed by Ben Johnson
1 parent 92564315
Exists in master

Modified the code so that settingslogic doesn't raise an exception when environm…

…ent specific settings aren't defined. Environment specific settings now also work when initializing Settings with a Hash.

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
Showing 1 changed file with 4 additions and 1 deletions   Show diff stats
lib/settingslogic/settings.rb
... ... @@ -40,10 +40,13 @@ module Settingslogic
40 40 root_path = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config/" : ""
41 41 file_path = name_or_hash.is_a?(Symbol) ? "#{root_path}#{name_or_hash}.yml" : name_or_hash
42 42 self.update YAML.load(ERB.new(File.read(file_path)).result).to_hash
43   - self.update self[RAILS_ENV] if defined?(RAILS_ENV)
44 43 else
45 44 raise ArgumentError.new("Your settings must be a hash, a symbol representing the name of the .yml file in your config directory, or a string representing the abosolute path to your settings file.")
46 45 end
  46 + if defined?(RAILS_ENV)
  47 + rails_env = self.keys.include?(RAILS_ENV) ? RAILS_ENV : RAILS_ENV.to_sym
  48 + self.update self[rails_env] if self[rails_env]
  49 + end
47 50 define_settings!
48 51 end
49 52  
... ...