add validation for configuration

This commit is contained in:
Benjamin Neff 2015-06-16 02:49:37 +02:00
parent 96af095d84
commit aff5de85f9

View file

@ -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