Sha256: cd7abdad1cdd28cc5eedc1e5fc1ef7b3fe41279314b65ce65e02f5135807063f

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module UcbRails
  module Configuration
    
    class Ldap
      attr_accessor :config
      
      def initialize(config)
        self.config = config.presence || {}
      end
      
      def configure
        configure_host
        authenticate
        test_entries
      end
      
      private

      def configure_host
        UCB::LDAP.host = config.fetch('host', default_host)
      end

      def authenticate
        if config.has_key?('username')
          UCB::LDAP.authenticate config['username'], config['password']
        end
      end
      
      def test_entries
        UCB::LDAP::Person.include_test_entries = config.fetch('include_test_entries', default_include_test_entries)
      end
      
      def default_host
        RailsEnvironment.production? ? 'nds.berkeley.edu' : 'nds-test.berkeley.edu'
      end

      def default_include_test_entries
        RailsEnvironment.not_production?
      end
      
      class << self
        def configure(config)
          new(config).configure
        end
      end
    end
    
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ucb_rails-0.0.14 app/models/ucb_rails/configuration/ldap.rb
ucb_rails-0.0.13 app/models/ucb_rails/configuration/ldap.rb
ucb_rails-0.0.12 app/models/ucb_rails/configuration/ldap.rb
ucb_rails-0.0.11 app/models/ucb_rails/configuration/ldap.rb
ucb_rails-0.0.10 app/models/ucb_rails/configuration/ldap.rb
ucb_rails-0.0.9 app/models/ucb_rails/configuration/ldap.rb