Module: ActiveLdap::Configuration::ClassMethods
- Defined in:
- lib/active_ldap/configuration.rb
Constant Summary collapse
- CONNECTION_CONFIGURATION_KEYS =
[:uri, :base, :adapter]
- @@defined_configurations =
{}
Instance Method Summary collapse
- #configuration(key = nil) ⇒ Object
- #default_configuration ⇒ Object
- #define_configuration(key, config) ⇒ Object
- #defined_configurations ⇒ Object
- #ensure_configuration(config = nil) ⇒ Object
- #merge_configuration(user_configuration, target = self) ⇒ Object
- #prepare_configuration(configuration) ⇒ Object
- #remove_configuration_by_configuration(config) ⇒ Object
- #remove_connection_related_configuration(config) ⇒ Object
Instance Method Details
#configuration(key = nil) ⇒ Object
79 80 81 |
# File 'lib/active_ldap/configuration.rb', line 79 def configuration(key=nil) @@defined_configurations[key || active_connection_name] end |
#default_configuration ⇒ Object
52 53 54 |
# File 'lib/active_ldap/configuration.rb', line 52 def default_configuration DEFAULT_CONFIG.dup end |
#define_configuration(key, config) ⇒ Object
83 84 85 |
# File 'lib/active_ldap/configuration.rb', line 83 def define_configuration(key, config) @@defined_configurations[key] = config end |
#defined_configurations ⇒ Object
87 88 89 |
# File 'lib/active_ldap/configuration.rb', line 87 def defined_configurations @@defined_configurations end |
#ensure_configuration(config = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_ldap/configuration.rb', line 56 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 |
#merge_configuration(user_configuration, target = self) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/active_ldap/configuration.rb', line 102 def merge_configuration(user_configuration, target=self) configuration = default_configuration 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 = _(":ldap_scope configuration option is deprecated. " \ "Use :scope instead.") ActiveSupport::Deprecation.warn() end target.scope = value configuration[:scope] = value else configuration[key] = value end end configuration end |
#prepare_configuration(configuration) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/active_ldap/configuration.rb', line 124 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 uri_configuration = {:port => uri.port} uri_configuration[:host] = uri.host if uri.host uri_configuration[:bind_dn] = uri.dn if uri.dn uri_configuration[:scope] = uri.scope if uri.scope uri_configuration[:method] = :ssl if uri.is_a?(URI::LDAPS) uri_configuration.merge(configuration) end |
#remove_configuration_by_configuration(config) ⇒ Object
91 92 93 |
# File 'lib/active_ldap/configuration.rb', line 91 def remove_configuration_by_configuration(config) @@defined_configurations.delete_if {|key, value| value == config} end |
#remove_connection_related_configuration(config) ⇒ Object
96 97 98 99 100 |
# File 'lib/active_ldap/configuration.rb', line 96 def (config) config.reject do |key, value| CONNECTION_CONFIGURATION_KEYS.include?(key) end end |