Module: ActiveLdap::Configuration::ClassMethods
- Defined in:
- lib/active_ldap/configuration.rb
Constant Summary collapse
- CONNECTION_CONFIGURATION_KEYS =
[: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(config, target = self) ⇒ Object
- #remove_configuration_by_configuration(config) ⇒ Object
- #remove_connection_related_configuration(config) ⇒ Object
Instance Method Details
#configuration(key = nil) ⇒ Object
67 68 69 |
# File 'lib/active_ldap/configuration.rb', line 67 def configuration(key=nil) @@defined_configurations[key || active_connection_name] end |
#default_configuration ⇒ Object
40 41 42 |
# File 'lib/active_ldap/configuration.rb', line 40 def default_configuration DEFAULT_CONFIG.dup end |
#define_configuration(key, config) ⇒ Object
71 72 73 |
# File 'lib/active_ldap/configuration.rb', line 71 def define_configuration(key, config) @@defined_configurations[key] = config end |
#defined_configurations ⇒ Object
75 76 77 |
# File 'lib/active_ldap/configuration.rb', line 75 def defined_configurations @@defined_configurations end |
#ensure_configuration(config = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/active_ldap/configuration.rb', line 44 def ensure_configuration(config=nil) if config.nil? if defined?(LDAP_ENV) config = LDAP_ENV elsif defined?(RAILS_ENV) 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(config, target = self) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/active_ldap/configuration.rb', line 90 def merge_configuration(config, target=self) configuration = default_configuration config.symbolize_keys.each do |key, value| case key when :base # Scrub before inserting target.base = value.gsub(/['}{#]/, '') when :scope, :ldap_scope if key == :ldap_scope logger.warning do _(":ldap_scope configuration option is deprecated. " \ "Use :scope instead.") end end target.scope = value configuration[:scope] = value else configuration[key] = value end end configuration end |
#remove_configuration_by_configuration(config) ⇒ Object
79 80 81 |
# File 'lib/active_ldap/configuration.rb', line 79 def remove_configuration_by_configuration(config) @@defined_configurations.delete_if {|key, value| value == config} end |
#remove_connection_related_configuration(config) ⇒ Object
84 85 86 87 88 |
# File 'lib/active_ldap/configuration.rb', line 84 def (config) config.reject do |key, value| CONNECTION_CONFIGURATION_KEYS.include?(key) end end |