lib/shoppe.rb in shoppe-0.0.8 vs lib/shoppe.rb in shoppe-0.0.9

- old
+ new

@@ -22,18 +22,44 @@ if File.exist?(path) config = YAML.load_file(path).with_indifferent_access setup_config(config) config else - $stderr.puts "Shoppe configuration file missing at #{path}" - {} + raise InvalidConfiguration, "Shoppe configuration file missing at #{path}" end end end def setup_config(config) ActionMailer::Base.smtp_settings = config[:smtp_settings] if config[:smtp_settings] end + + def validate_live_config(*requirements) + validate_config(self.config, [], *requirements) + end + + def validate_config(config, scope, *requirements) + for req in requirements + case req + when String, Symbol + unless config.keys.include?(req.to_s) + raise Shoppe::Errors::InvalidConfiguration, "Missing configuration option '#{scope.join('.')}.#{req}' in shoppe.yml" + end + when Array + validate_config(config, scope, *req) + when Hash + req.each do |key, value| + if config[key] && config[key].is_a?(Hash) + scope << key + validate_config(config[key], scope, *value) + else + validate_config(config, scope, key) + end + end + end + end + end + end end # Start your engines.