From aff5de85f9e81ccf989bd14f9e83f8950f10efa3 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Tue, 16 Jun 2015 02:49:37 +0200 Subject: [PATCH] add validation for configuration --- lib/diaspora_federation.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/diaspora_federation.rb b/lib/diaspora_federation.rb index 80dd47f..572189e 100644 --- a/lib/diaspora_federation.rb +++ b/lib/diaspora_federation.rb @@ -34,7 +34,39 @@ module DiasporaFederation # end def configure yield self + validate_config logger.info "successfully configured the federation engine" end + + private + + def validate_config + raise ConfigurationError, "missing server_uri" unless @server_uri.respond_to? :host + validate_class(@person_class, "person_class", %i( + find_local_by_diaspora_handle + guid + url + diaspora_handle + serialized_public_key + salmon_url + atom_url + profile_url + hcard_url + )) + end + + def validate_class(klass, name, methods) + raise ConfigurationError, "missing #{name}" unless klass + const = const_get(klass) + methods.each {|method| + valid = const.respond_to?(method) || const.column_names.include?(method.to_s) || const.method_defined?(method) + raise ConfigurationError, "the configured class #{const} for #{name} does not respond to #{method}" unless valid + } + end + end + + ## + # raised, if the engine is not configured correctly + class ConfigurationError < RuntimeError end end