lib/yaml2env.rb in yaml2env-0.1.1 vs lib/yaml2env.rb in yaml2env-0.1.2

- old
+ new

@@ -53,11 +53,11 @@ def configure yield self end - def load(config_path, required_keys = {}, optional_keys = {}) + def load!(config_path, required_keys = {}, optional_keys = {}) self.detect_root! self.detect_env! config ||= {} @@ -82,19 +82,34 @@ ::Yaml2env::LOADED_ENV[env_key.to_s] || raise(MissingConfigKeyError, "ENV variable '#{env_key}' needs to be set. Query: #{keys_values.inspect}. Found: #{config.inspect}") end end + def load(config_path, required_keys = {}, optional_keys = {}) + begin + self.load!(config_path, required_keys, optional_keys) + rescue Error => e + if self.logger? + ::Yaml2env.logger.warn("[Yaml2env]: #{e} -- called from: #{__FILE__})") + end + end + true + end + + def loaded?(*constant_names) + constant_names.all? { |cn| ::Yaml2env::LOADED_ENV.key?(cn.to_s) } + end + def detect_root! self.root ||= if ::ENV.key?('RACK_ROOT') ::ENV['RACK_ROOT'] elsif defined?(::Rails) ::Rails.root elsif defined?(::Sinatra::Application) ::Sinatra::Application.root else - raise DetectionFailedError, "Failed to auto-detect Yaml.env (config environment). Specify environment before loading any configs/initializers using Yaml2env, e.g Yaml2env.env = 'development'." + raise DetectionFailedError, "Failed to auto-detect Yaml.root (config root). Specify root before loading any configs/initializers using Yaml2env, e.g. Yaml2env.root = '~/projects/my_app'." end end def detect_env! self.env ||= if ::ENV.key?('RACK_ENV') @@ -102,10 +117,10 @@ elsif defined?(::Rails) ::Rails.env elsif defined?(::Sinatra::Application) ::Sinatra::Application.environment else - raise DetectionFailedError, "Failed to auto-detect Yaml2env.root (config root). Specify environment before loading any configs/initializers using Yaml2env, e.g Yaml2env.env = 'development'." + raise DetectionFailedError, "Failed to auto-detect Yaml2env.root (config root). Specify environment before loading any configs/initializers using Yaml2env, e.g. Yaml2env.env = 'development'." end end def logger? self.logger.respond_to?(:info)