module ActiveLdap::Configuration::ClassMethods
def configuration(key=nil)
def configuration(key=nil) @@defined_configurations[key || active_connection_name] end
def default_configuration
def default_configuration DEFAULT_CONFIG.dup end
def define_configuration(key, config)
def define_configuration(key, config) @@defined_configurations[key] = config end
def defined_configurations
def defined_configurations @@defined_configurations end
def ensure_configuration(config=nil)
def ensure_configuration(config=nil) if config.nil? if defined?(LDAP_ENV) config = LDAP_ENV elsif defined?(Rails) config = Rails.env else config = {} end end if config.is_a?(Symbol) or config.is_a?(String) _config = configurations[config.to_s] unless _config raise ConnectionError, _("%s connection is not configured") % config end config = _config end config end
def merge_configuration(user_configuration, target=self)
def merge_configuration(user_configuration, target=self) configuration = parent_configuration(target).dup prepare_configuration(user_configuration).each do |key, value| case key when :base # Scrub before inserting target.base = value.gsub(/['}{#]/, '') when :scope, :ldap_scope if key == :ldap_scope message = _(":ldap_scope configuration option is deprecated. " \ "Use :scope instead.") ActiveLdap.deprecator.warn(message) end target.scope = value configuration[:scope] = value else configuration[key] = value end end configuration end
def parent_configuration(target)
def parent_configuration(target) if target.is_a?(Base) target = target.class else target = target.superclass end while target <= Base config = defined_configurations[target.active_connection_key] return config if config target = target.superclass end default_configuration end
def prepare_configuration(configuration)
def prepare_configuration(configuration) configuration = configuration.symbolize_keys uri = configuration.delete(:uri) return configuration unless uri begin uri = URI.parse(uri) rescue URI::InvalidURIError raise ConfigurationError.new(_("invalid URI: %s") % uri) end unless uri.is_a?(URI::LDAP) raise ConfigurationError.new(_("not a LDAP URI: %s") % uri.to_s) end merger = URIConfigurationMerger.new(uri) merger.merge(configuration) end
def remove_configuration_by_key(key)
def remove_configuration_by_key(key) @@defined_configurations.delete(key) end
def remove_connection_related_configuration(config)
def remove_connection_related_configuration(config) config.reject do |key, value| CONNECTION_CONFIGURATION_KEYS.include?(key) end end