mit-ldap 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,6 @@ gem 'mit-ldap'
12
12
 
13
13
  ```ruby
14
14
  require 'mit-ldap'
15
- MIT::LDAP.connect!
16
- MIT::LDAP.search(:filter => '(uid=mrhalp)') # any Ldaptic syntax
15
+ MIT::LDAP.connect! # true
16
+ MIT::LDAP.search(:filter => '(uid=mrhalp)') # any Ldaptic options/methods
17
17
  ```
@@ -15,9 +15,9 @@ module MIT
15
15
  def ip_addresses
16
16
  if RbConfig::CONFIG['host_os'] =~ /darwin/
17
17
  `ifconfig | awk '/inet / {print $2}'`
18
- else
19
- `ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p'`
20
- end
18
+ else
19
+ `ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p'`
20
+ end
21
21
  end
22
22
  end
23
23
  end
@@ -1,23 +1,27 @@
1
1
  module MIT
2
2
  module LDAP
3
3
 
4
- class << self
5
- attr_accessor :connection
6
- end
7
-
8
4
  def self.connect!
9
5
  if MIT.on_campus?
10
- self.connection = ::LDAP::Conn.new('ldap-too.mit.edu')
6
+ ldap_connection = ::LDAP::Conn.new('ldap-too.mit.edu')
11
7
  singleton_class.send(:include,
12
8
  Ldaptic::Module(
13
9
  :adapter => :ldap_conn,
14
- :connection => connection,
10
+ :connection => ldap_connection,
15
11
  :host => 'ldap-too.mit.edu',
16
12
  :base => 'dc=mit,dc=edu',
17
13
  )
18
14
  )
19
15
  end
20
- return !self.connection.nil?
16
+ return connected?
17
+ end
18
+
19
+ def self.connection
20
+ respond_to?(:adapter) ? adapter.instance_variable_get(:@connection) : nil
21
+ end
22
+
23
+ def self.connected?
24
+ !self.connection.nil?
21
25
  end
22
26
  end
23
27
  end
@@ -1,5 +1,5 @@
1
1
  module MIT
2
2
  module LDAP
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'mit-ldap'
2
+ require 'ldaptic/adapters/ldap_conn_adapter'
2
3
 
3
4
  module MIT
4
5
  describe LDAP do
@@ -9,10 +10,18 @@ module MIT
9
10
  # Server is not properly configured so the attributes required
10
11
  # by Ldaptic when configuring class hierarchy do not exist resulting
11
12
  # searches failing (i.e., this method should only be used to get around
12
- # ldap-too only being accessible from campus
13
+ # ldap-too only being accessible from campus)
14
+ let!(:connection) { ::LDAP::Conn.new('ldap.mit.edu') }
15
+
13
16
  def stub_ldap_connection
14
- @connection = ::LDAP::Conn.new('ldap.mit.edu')
15
- ::LDAP::Conn.stub(:new).and_return(@connection)
17
+ ::LDAP::Conn.stub(:new).and_return(connection)
18
+ stub_ldaptic_adapter(connection)
19
+ end
20
+
21
+ def stub_ldaptic_adapter(connection = nil)
22
+ adapter = double('adapter')
23
+ adapter.stub(:instance_variable_get).with(:@connection).and_return(connection)
24
+ LDAP.stub(:adapter).and_return(adapter)
16
25
  end
17
26
 
18
27
  def stub_ldaptic_include
@@ -21,6 +30,7 @@ module MIT
21
30
 
22
31
  describe ".connect!" do
23
32
  describe "when off campus" do
33
+
24
34
  it "returns false" do
25
35
  MIT.stub(:on_campus?).and_return(false)
26
36
  LDAP.connect!.should be_false
@@ -43,7 +53,7 @@ module MIT
43
53
  Ldaptic.should_receive(:Module).
44
54
  with(:adapter => :ldap_conn,
45
55
  :base => 'dc=mit,dc=edu',
46
- :connection => @connection,
56
+ :connection => connection,
47
57
  :host => 'ldap-too.mit.edu'
48
58
  )
49
59
  LDAP.connect!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mit-ldap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ldaptic
16
- requirement: &70314214948620 !ruby/object:Gem::Requirement
16
+ requirement: &70184617094400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70314214948620
24
+ version_requirements: *70184617094400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-ldap
27
- requirement: &70314214948120 !ruby/object:Gem::Requirement
27
+ requirement: &70184617093880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70314214948120
35
+ version_requirements: *70184617093880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70314214947620 !ruby/object:Gem::Requirement
38
+ requirement: &70184617093400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70314214947620
46
+ version_requirements: *70184617093400
47
47
  description: Ruby interface for querying MIT LDAP server (only if you're on MITnet)
48
48
  email:
49
49
  - edd_d@mit.edu