add validation for configuration
This commit is contained in:
parent
96af095d84
commit
aff5de85f9
1 changed files with 32 additions and 0 deletions
|
|
@ -34,7 +34,39 @@ module DiasporaFederation
|
||||||
# end
|
# end
|
||||||
def configure
|
def configure
|
||||||
yield self
|
yield self
|
||||||
|
validate_config
|
||||||
logger.info "successfully configured the federation engine"
|
logger.info "successfully configured the federation engine"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue