ambitious-activeldap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +8 -0
- data/ambitious-activeldap.gemspec +55 -0
- data/lib/ambition/adapters/active_ldap/base.rb +15 -0
- data/lib/ambition/adapters/active_ldap/query.rb +27 -0
- data/lib/ambition/adapters/active_ldap/select.rb +65 -0
- data/test/enumerable_test.rb +95 -0
- data/test/helper.rb +17 -0
- data/test/integration_test.rb +7 -0
- data/test/select_test.rb +83 -0
- metadata +73 -0
data/Manifest
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
# Gem::Specification for Ambitious-activeldap-0.1.0
|
3
|
+
# Originally generated by Echoe
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{ambitious-activeldap}
|
7
|
+
s.version = "0.1.0"
|
8
|
+
s.date = %q{2008-01-29}
|
9
|
+
s.summary = %q{An ambitious adapter for ActiveLDAP}
|
10
|
+
s.email = %q{chris@ozmm.org}
|
11
|
+
s.homepage = %q{http://ambition.rubyforge.org/}
|
12
|
+
s.rubyforge_project = %q{ambition}
|
13
|
+
s.description = %q{An ambitious adapter for ActiveLDAP}
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.authors = ["Chris Wanstrath"]
|
16
|
+
s.files = ["lib/ambition/adapters/active_ldap/base.rb", "lib/ambition/adapters/active_ldap/query.rb", "lib/ambition/adapters/active_ldap/select.rb", "test/enumerable_test.rb", "test/helper.rb", "test/integration_test.rb", "test/select_test.rb", "Manifest", "ambitious-activeldap.gemspec"]
|
17
|
+
s.test_files = ["test/enumerable_test.rb", "test/integration_test.rb", "test/select_test.rb"]
|
18
|
+
s.add_dependency(%q<ruby-activeldap>, [">= 0.8.3.1"])
|
19
|
+
s.add_dependency(%q<ambition>, [">= 0.5.0"])
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# # Original Rakefile source (requires the Echoe gem):
|
24
|
+
#
|
25
|
+
# require 'rake'
|
26
|
+
#
|
27
|
+
# Version = '0.1.0'
|
28
|
+
#
|
29
|
+
# begin
|
30
|
+
# require 'rubygems'
|
31
|
+
# gem 'echoe', '>=2.7'
|
32
|
+
# ENV['RUBY_FLAGS'] = ""
|
33
|
+
# require 'echoe'
|
34
|
+
#
|
35
|
+
# Echoe.new('ambitious-activeldap') do |p|
|
36
|
+
# p.dependencies << 'ruby-activeldap >=0.8.3.1'
|
37
|
+
# p.summary = "An ambitious adapter for ActiveLDAP"
|
38
|
+
# p.author = 'Chris Wanstrath'
|
39
|
+
# p.email = "chris@ozmm.org"
|
40
|
+
#
|
41
|
+
# p.project = 'ambition'
|
42
|
+
# p.url = "http://ambition.rubyforge.org/"
|
43
|
+
# p.test_pattern = 'test/*_test.rb'
|
44
|
+
# p.version = Version
|
45
|
+
# p.dependencies << 'ambition >=0.5.0'
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# rescue LoadError
|
49
|
+
# puts "Not doing any of the Echoe gemmy stuff, because you don't have the specified gem versions"
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# desc 'Install as a gem'
|
53
|
+
# task :install_gem do
|
54
|
+
# puts `rake manifest package && gem install pkg/ambitious-activeldap-#{Version}.gem`
|
55
|
+
# end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Ambition
|
2
|
+
module Adapters
|
3
|
+
module ActiveLdap
|
4
|
+
class Query
|
5
|
+
|
6
|
+
def kick
|
7
|
+
owner.find(:all, to_hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
def size
|
11
|
+
raise "Not Implemented"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
hash = {}
|
16
|
+
hash[:filter] = to_s unless to_s.empty?
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
Array(clauses[:select]).join
|
22
|
+
clauses[:select].first.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Ambition
|
2
|
+
module Adapters
|
3
|
+
module ActiveLdap
|
4
|
+
class Select < Base
|
5
|
+
def call(*methods)
|
6
|
+
method = methods.first.to_s
|
7
|
+
if method[-1] == ??
|
8
|
+
"(#{method[0...-1]}=#{sanitize true})"
|
9
|
+
else
|
10
|
+
method
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def chained_call(*methods)
|
15
|
+
call(*methods)
|
16
|
+
end
|
17
|
+
|
18
|
+
def both(left, right)
|
19
|
+
"(&#{left}#{sanitize right})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def either(left, right)
|
23
|
+
"(|#{left}#{sanitize right})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def ==(left, right)
|
27
|
+
"(#{left}=#{sanitize right})"
|
28
|
+
end
|
29
|
+
|
30
|
+
# !=
|
31
|
+
def not_equal(left, right)
|
32
|
+
"(!(#{left}=#{sanitize right}))"
|
33
|
+
end
|
34
|
+
|
35
|
+
def =~(left, right)
|
36
|
+
end
|
37
|
+
|
38
|
+
# !~
|
39
|
+
def not_regexp(left, right)
|
40
|
+
end
|
41
|
+
|
42
|
+
def <(left, right)
|
43
|
+
self.<=(left, right)
|
44
|
+
end
|
45
|
+
|
46
|
+
def >(left, right)
|
47
|
+
self.>=(left, right)
|
48
|
+
end
|
49
|
+
|
50
|
+
def >=(left, right)
|
51
|
+
"(#{left}>=#{sanitize right})"
|
52
|
+
end
|
53
|
+
|
54
|
+
def <=(left, right)
|
55
|
+
"(#{left}<=#{sanitize right})"
|
56
|
+
end
|
57
|
+
|
58
|
+
def include?(left, right)
|
59
|
+
bits = left.map { |item| "(#{right}=#{item})" }
|
60
|
+
"(|#{bits})"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "Each" do
|
4
|
+
specify "simple ==" do
|
5
|
+
hash = { :filter => "(uid=mking)" }
|
6
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
7
|
+
LDAPUser.select { |m| m.uid == 'mking' }.each do |user|
|
8
|
+
puts user.cn
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
xspecify "limit and conditions" do
|
13
|
+
hash = { :limit => 5, :filter => "(uid=mking)" }
|
14
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
15
|
+
LDAPUser.select { |m| m.uid == 'mking' }.first(5).each do |user|
|
16
|
+
puts user.cn
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
xspecify "limit and conditions and order" do
|
21
|
+
hash = { :limit => 5, :filter => "(uid=mking)", :sort_by => 'sn' }
|
22
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
23
|
+
LDAPUser.select { |m| m.uid == 'mking' }.sort_by { |m| m.sn }.first(5).each do |user|
|
24
|
+
puts user.cn
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
xspecify "limit and order" do
|
29
|
+
hash = { :limit => 5, :sort_by => 'sn' }
|
30
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
31
|
+
LDAPUser.sort_by { |m| m.sn }.first(5).each do |user|
|
32
|
+
puts user.name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "Enumerable Methods" do
|
38
|
+
specify "map" do
|
39
|
+
hash = { :filter => "(uid=mking)" }
|
40
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
41
|
+
LDAPUser.select { |m| m.uid == 'mking' }.map { |u| u.name }
|
42
|
+
end
|
43
|
+
|
44
|
+
specify "each_with_index" do
|
45
|
+
hash = { :filter => "(uid=mking)" }
|
46
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
47
|
+
LDAPUser.select { |m| m.uid == 'mking' }.each_with_index do |user, i|
|
48
|
+
puts "#{i}: #{user.name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# specify "any?" do
|
53
|
+
# LDAPUser.expects(:count).with(:conditions => "users.age > 21").returns(1)
|
54
|
+
# LDAPUser.any? { |u| u.age > 21 }.should == true
|
55
|
+
# end
|
56
|
+
|
57
|
+
# specify "all?" do
|
58
|
+
# LDAPUser.expects(:count).at_least_once.returns(10, 20)
|
59
|
+
# LDAPUser.all? { |u| u.age > 21 }.should == false
|
60
|
+
#
|
61
|
+
# LDAPUser.expects(:count).at_least_once.returns(10, 10)
|
62
|
+
# LDAPUser.all? { |u| u.age > 21 }.should == true
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# specify "empty?" do
|
66
|
+
# LDAPUser.expects(:count).with(:conditions => "users.age > 21").returns(1)
|
67
|
+
# LDAPUser.select { |u| u.age > 21 }.empty?.should.equal false
|
68
|
+
#
|
69
|
+
# LDAPUser.expects(:count).with(:conditions => "users.age > 21").returns(0)
|
70
|
+
# LDAPUser.select { |u| u.age > 21 }.empty?.should.equal true
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
specify "entries" do
|
74
|
+
LDAPUser.expects(:find).with(:all, {})
|
75
|
+
LDAPUser.entries
|
76
|
+
|
77
|
+
hash = { :filter => "(uid=mking)" }
|
78
|
+
LDAPUser.expects(:find).with(:all, hash).returns([])
|
79
|
+
LDAPUser.select { |m| m.uid == 'mking' }.entries
|
80
|
+
end
|
81
|
+
|
82
|
+
specify "to_a" do
|
83
|
+
LDAPUser.expects(:find).with(:all, {})
|
84
|
+
LDAPUser.to_a
|
85
|
+
end
|
86
|
+
#
|
87
|
+
# xspecify "each_slice" do
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# xspecify "max" do
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# xspecify "min" do
|
94
|
+
# end
|
95
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
%w( rubygems test/spec mocha redgreen English ).each { |f| require f }
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift *[ File.dirname(__FILE__) + '/../lib', File.dirname(__FILE__) + '/../../../lib' ]
|
4
|
+
require 'ambition/adapters/active_ldap'
|
5
|
+
|
6
|
+
ActiveLdap::Base.class_eval do
|
7
|
+
def self.find(*args)
|
8
|
+
'dummy find method'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class LDAPUser < ActiveLdap::Base
|
13
|
+
def self.table_name
|
14
|
+
# in real life would call the base class method on the ActiveLdap model class
|
15
|
+
'ou=people,dc=automatthew,dc=com'
|
16
|
+
end
|
17
|
+
end
|
data/test/select_test.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
|
3
|
+
context "LDAP Adapter :: Select" do
|
4
|
+
context "Filter (using select)" do
|
5
|
+
specify "simple ==" do
|
6
|
+
filter = LDAPUser.select { |m| m.name == 'jon' }.to_s
|
7
|
+
filter.should == "(name=jon)"
|
8
|
+
end
|
9
|
+
|
10
|
+
specify "simple !=" do
|
11
|
+
filter = LDAPUser.select { |m| m.name != 'jon' }.to_s
|
12
|
+
filter.should == "(!(name=jon))"
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "simple == && ==" do
|
16
|
+
filter = LDAPUser.select { |m| m.name == 'jon' && m.age == 21 }.to_s
|
17
|
+
filter.should == "(&(name=jon)(age=21))"
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "simple == || ==" do
|
21
|
+
filter = LDAPUser.select { |m| m.name == 'jon' || m.age == 21 }.to_s
|
22
|
+
filter.should == "(|(name=jon)(age=21))"
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "mixed && and ||" do
|
26
|
+
filter = LDAPUser.select { |m| m.name == 'jon' || m.age == 21 && m.password == 'pass' }.to_s
|
27
|
+
filter.should == "(|(name=jon)(&(age=21)(password=pass)))"
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "grouped && and ||" do
|
31
|
+
filter = LDAPUser.select { |m| (m.name == 'jon' || m.name == 'rick') && m.age == 21 }.to_s
|
32
|
+
filter.should == "(&(|(name=jon)(name=rick))(age=21))"
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "simple >/<" do
|
36
|
+
# LDAP apparently only supports >= and <=
|
37
|
+
filter = LDAPUser.select { |m| m.age > 21 }.to_s
|
38
|
+
filter.should == "(age>=21)"
|
39
|
+
|
40
|
+
filter = LDAPUser.select { |m| m.age >= 21 }.to_s
|
41
|
+
filter.should == "(age>=21)"
|
42
|
+
|
43
|
+
filter = LDAPUser.select { |m| m.age < 21 }.to_s
|
44
|
+
filter.should == "(age<=21)"
|
45
|
+
|
46
|
+
filter = LDAPUser.select { |m| m.age <= 21 }.to_s
|
47
|
+
filter.should == "(age<=21)"
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "array.include? item" do
|
51
|
+
filter = LDAPUser.select { |m| [1, 2, 3, 4].include? m.id }.to_s
|
52
|
+
# I'm not sure whether this is idiomatic, but it works.
|
53
|
+
filter.should == "(|(id=1)(id=2)(id=3)(id=4))"
|
54
|
+
end
|
55
|
+
|
56
|
+
specify "variable'd array.include? item" do
|
57
|
+
array = [1, 2, 3, 4]
|
58
|
+
filter = LDAPUser.select { |m| array.include? m.id }.to_s
|
59
|
+
filter.should == "(|(id=1)(id=2)(id=3)(id=4))"
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "simple == with variables" do
|
63
|
+
me = 'chris'
|
64
|
+
filter = LDAPUser.select { |m| m.name == me }.to_s
|
65
|
+
filter.should == "(name=#{me})"
|
66
|
+
end
|
67
|
+
|
68
|
+
specify "simple == with true" do
|
69
|
+
filter = LDAPUser.select { |m| m.disabled == true }.to_s
|
70
|
+
filter.should == "(disabled=TRUE)"
|
71
|
+
end
|
72
|
+
|
73
|
+
xspecify "implicit true" do
|
74
|
+
filter = LDAPUser.select { |m| m.disabled }.to_s
|
75
|
+
filter.should == "(disabled=TRUE)"
|
76
|
+
end
|
77
|
+
|
78
|
+
specify "predicate method" do
|
79
|
+
filter = LDAPUser.select { |m| m.disabled? }.to_s
|
80
|
+
filter.should == "(disabled=TRUE)"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: ambitious-activeldap
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2008-01-29 00:00:00 -08:00
|
8
|
+
summary: An ambitious adapter for ActiveLDAP
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: chris@ozmm.org
|
12
|
+
homepage: http://ambition.rubyforge.org/
|
13
|
+
rubyforge_project: ambition
|
14
|
+
description: An ambitious adapter for ActiveLDAP
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Chris Wanstrath
|
31
|
+
files:
|
32
|
+
- lib/ambition/adapters/active_ldap/base.rb
|
33
|
+
- lib/ambition/adapters/active_ldap/query.rb
|
34
|
+
- lib/ambition/adapters/active_ldap/select.rb
|
35
|
+
- test/enumerable_test.rb
|
36
|
+
- test/helper.rb
|
37
|
+
- test/integration_test.rb
|
38
|
+
- test/select_test.rb
|
39
|
+
- Manifest
|
40
|
+
- ambitious-activeldap.gemspec
|
41
|
+
test_files:
|
42
|
+
- test/enumerable_test.rb
|
43
|
+
- test/integration_test.rb
|
44
|
+
- test/select_test.rb
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
extra_rdoc_files: []
|
48
|
+
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
dependencies:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: ruby-activeldap
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.8.3.1
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: ambition
|
67
|
+
version_requirement:
|
68
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.5.0
|
73
|
+
version:
|