mit-ldap 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,17 +7,14 @@ module MIT
7
7
  class << self
8
8
 
9
9
  def on_campus?
10
- ip_addresses.split(/\n/).map { |ip| !(ip =~ /^18\./).nil? }.any?
10
+ ip_addresses.map { |ip| !(ip =~ /^18\./).nil? }.any?
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def ip_addresses
16
- if RbConfig::CONFIG['host_os'] =~ /darwin/
17
- `ifconfig | awk '/inet / {print $2}'`
18
- else
19
- `ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p'`
20
- end
16
+ ifconfig = `ifconfig`
17
+ @ip_addresses ||= ifconfig.split(/\n/).grep(/inet (?:addr:)?((?:\d{1,3}\.){3}\d{1,3})/) { $1 }
21
18
  end
22
19
  end
23
20
  end
@@ -19,7 +19,7 @@ module MIT
19
19
  end
20
20
 
21
21
  def reconnect!
22
- if adapter_present? && !connected?
22
+ if adapter_present?
23
23
  adapter.instance_variable_set(:@connection, ::LDAP::Conn.new('ldap-too.mit.edu'))
24
24
  elsif !adapter_present?
25
25
  connect!
@@ -1,5 +1,5 @@
1
1
  module MIT
2
2
  module LDAP
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
@@ -27,13 +27,13 @@ module MIT
27
27
  end
28
28
 
29
29
  describe ".reconnect!" do
30
- it "reloads connection object if nil" do
30
+ it "reloads connection object" do
31
31
  LDAP.adapter.instance_variable_set(:@connection, nil)
32
32
  LDAP.reconnect!
33
33
  LDAP.adapter.instance_variable_get(:@connection).should be_a ::LDAP::Conn
34
34
  end
35
35
 
36
- it "calls .connect! if not connected" do
36
+ it "calls .connect! if not connected already" do
37
37
  LDAP.stub(:adapter_present?).and_return(false)
38
38
  LDAP.should_receive(:connect!)
39
39
  LDAP.reconnect!
@@ -4,12 +4,12 @@ describe MIT do
4
4
 
5
5
  describe ".on_campus?" do
6
6
  it "returns true if IP starts with 18" do
7
- MIT.stub(:ip_addresses).and_return("18.0.0.0\n127.0.0.1")
7
+ MIT.stub(:ip_addresses).and_return(['18.0.0.0', '127.0.0.1'])
8
8
  MIT.on_campus?.should be_true
9
9
  end
10
10
 
11
11
  it "returns false if no network device has a campus address" do
12
- MIT.stub(:ip_addresses).and_return("192.168.1.2\n127.0.0.1")
12
+ MIT.stub(:ip_addresses).and_return(['192.168.0.2', '127.0.0.1'])
13
13
  MIT.on_campus?.should be_false
14
14
  end
15
15
  end
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.3.0
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-14 00:00:00.000000000 Z
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ldaptic
16
- requirement: &70320703308640 !ruby/object:Gem::Requirement
16
+ requirement: &70295147816060 !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: *70320703308640
24
+ version_requirements: *70295147816060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby-ldap
27
- requirement: &70320703308140 !ruby/object:Gem::Requirement
27
+ requirement: &70295147813080 !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: *70320703308140
35
+ version_requirements: *70295147813080
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70320703307680 !ruby/object:Gem::Requirement
38
+ requirement: &70295147810340 !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: *70320703307680
46
+ version_requirements: *70295147810340
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