ruby-activeldap 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/activeldap/base.rb +67 -15
- data/lib/activeldap.rb +11 -2
- metadata +2 -2
data/lib/activeldap/base.rb
CHANGED
@@ -358,7 +358,7 @@ module ActiveLDAP
|
|
358
358
|
dnval = m.dn.split(/,/)[0].split(/=/)[1]
|
359
359
|
|
360
360
|
if objects
|
361
|
-
return eval("#{real_klass}.new(
|
361
|
+
return eval("#{real_klass}.new(m)")
|
362
362
|
else
|
363
363
|
return dnval
|
364
364
|
end
|
@@ -392,8 +392,8 @@ module ActiveLDAP
|
|
392
392
|
end
|
393
393
|
|
394
394
|
# Allow a single string argument
|
395
|
-
objects = false
|
396
395
|
val = config
|
396
|
+
objects = false
|
397
397
|
# Or a hash
|
398
398
|
if config.respond_to?"has_key?"
|
399
399
|
attr = config[:attribute] || dnattr()
|
@@ -410,7 +410,7 @@ module ActiveLDAP
|
|
410
410
|
dnval = m.dn.split(/,/)[0].split(/=/)[1]
|
411
411
|
|
412
412
|
if objects
|
413
|
-
matches.push(eval("#{real_klass}.new(
|
413
|
+
matches.push(eval("#{real_klass}.new(m)"))
|
414
414
|
else
|
415
415
|
matches.push(dnval)
|
416
416
|
end
|
@@ -462,20 +462,20 @@ module ActiveLDAP
|
|
462
462
|
[]
|
463
463
|
end
|
464
464
|
|
465
|
+
|
466
|
+
|
465
467
|
### All instance methods, etc
|
466
468
|
|
467
469
|
# new
|
468
470
|
#
|
469
|
-
# Creates a new instance of Base initializing all class and
|
470
|
-
#
|
471
|
-
#
|
472
|
-
#
|
473
|
-
#
|
474
|
-
#
|
471
|
+
# Creates a new instance of Base initializing all class and all
|
472
|
+
# initialization. Defines local defaults. See examples If multiple values
|
473
|
+
# exist for dnattr, the first one put here will be authoritative
|
474
|
+
# TODO: Add # support for relative distinguished names
|
475
|
+
# val can be a dn attribute value, a full DN, or a LDAP::Entry. The use
|
476
|
+
# with a LDAP::Entry is primarily meant for internal use by find and
|
477
|
+
# find_all.
|
475
478
|
def initialize(val='')
|
476
|
-
if val.class != String
|
477
|
-
raise TypeError, "Object key must be a String"
|
478
|
-
end
|
479
479
|
# Try a default connection if none made explicitly
|
480
480
|
unless Base.connection
|
481
481
|
# Use @@config if it has been prepopulated and the conn is down.
|
@@ -485,6 +485,16 @@ module ActiveLDAP
|
|
485
485
|
ActiveLDAP::Base.connect
|
486
486
|
end
|
487
487
|
end
|
488
|
+
if val.class == LDAP::Entry
|
489
|
+
# Call import, which is basically initialize
|
490
|
+
# without accessing LDAP.
|
491
|
+
@@logger.debug "initialize: val is a LDAP::Entry - running import."
|
492
|
+
import(val)
|
493
|
+
return
|
494
|
+
end
|
495
|
+
if val.class != String
|
496
|
+
raise TypeError, "Object key must be a String"
|
497
|
+
end
|
488
498
|
|
489
499
|
@data = {} # where the r/w entry data is stored
|
490
500
|
@data.default = []
|
@@ -551,7 +561,7 @@ module ActiveLDAP
|
|
551
561
|
send(attr_sym, val)
|
552
562
|
end
|
553
563
|
end
|
554
|
-
end #
|
564
|
+
end # initialize
|
555
565
|
|
556
566
|
# Hide new in Base
|
557
567
|
private_class_method :new
|
@@ -845,6 +855,50 @@ module ActiveLDAP
|
|
845
855
|
|
846
856
|
private
|
847
857
|
|
858
|
+
# import(LDAP::Entry)
|
859
|
+
#
|
860
|
+
# Overwrites an existing entry (usually called by new)
|
861
|
+
# with the data given in the data given in LDAP::Entry.
|
862
|
+
#
|
863
|
+
def import(entry=nil)
|
864
|
+
@@logger.debug("stub: import called")
|
865
|
+
if entry.class != LDAP::Entry
|
866
|
+
raise TypeError, "argument must be a LDAP::Entry"
|
867
|
+
end
|
868
|
+
|
869
|
+
@data = {} # where the r/w entry data is stored
|
870
|
+
@data.default = []
|
871
|
+
@ldap_data = {} # original ldap entry data
|
872
|
+
@ldap_data.default = []
|
873
|
+
@attr_methods = {} # list of valid method calls for attributes used for dereferencing
|
874
|
+
|
875
|
+
# Get some attributes
|
876
|
+
@dn = entry.dn
|
877
|
+
entry.attrs.each do |attr|
|
878
|
+
# Load with subtypes just like @data
|
879
|
+
@@logger.debug("calling make_subtypes for entry.vals(attr).dup")
|
880
|
+
safe_attr, value = make_subtypes(attr, entry.vals(attr).dup)
|
881
|
+
@@logger.debug("finished make_subtypes for #{attr}")
|
882
|
+
# Add subtype to any existing values
|
883
|
+
if @ldap_data.has_key? safe_attr
|
884
|
+
value.each do |v|
|
885
|
+
@ldap_data[safe_attr].push(v)
|
886
|
+
end
|
887
|
+
else
|
888
|
+
@ldap_data[safe_attr] = value
|
889
|
+
end
|
890
|
+
end
|
891
|
+
# Assume if we are importing it that it exists
|
892
|
+
@exists = true
|
893
|
+
# Populate schema data
|
894
|
+
send(:apply_objectclass, @ldap_data['objectClass'])
|
895
|
+
|
896
|
+
# Populate real data now that we have the schema with aliases
|
897
|
+
@ldap_data.each do |pair|
|
898
|
+
send(:attribute_method=, pair[0], pair[1].dup)
|
899
|
+
end
|
900
|
+
end # import
|
901
|
+
|
848
902
|
# enforce_types
|
849
903
|
#
|
850
904
|
# enforce_types applies your changes without attempting to write to LDAP. This means that
|
@@ -860,8 +914,6 @@ module ActiveLDAP
|
|
860
914
|
return true
|
861
915
|
end
|
862
916
|
|
863
|
-
|
864
|
-
|
865
917
|
# apply_objectclass
|
866
918
|
#
|
867
919
|
# objectClass= special case for updating appropriately
|
data/lib/activeldap.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby -W0
|
2
2
|
# = Ruby/ActiveLDAP
|
3
3
|
#
|
4
|
-
# "Ruby/ActiveLDAP" Copyright (C) 2004 Will Drewry mailto:will@alum.bu.edu
|
4
|
+
# "Ruby/ActiveLDAP" Copyright (C) 2004,2005 Will Drewry mailto:will@alum.bu.edu
|
5
5
|
#
|
6
6
|
# == Introduction
|
7
7
|
#
|
@@ -795,6 +795,15 @@
|
|
795
795
|
# do all of your LDAP specific calls here and then continue about your normal
|
796
796
|
# Ruby/ActiveLDAP business afterward.
|
797
797
|
#
|
798
|
+
#
|
799
|
+
# ==== Reusing LDAP::Entry objects without reusing the LDAP connection
|
800
|
+
#
|
801
|
+
# You can call Klass.new(entry) where Klass is some subclass of Base and
|
802
|
+
# enty is an LDAP::entry. This use of 'new' is is meant for use from
|
803
|
+
# within find_all and find, but you can also use it in tandem with advanced
|
804
|
+
# LDAP queries.
|
805
|
+
#
|
806
|
+
# See tests/benchmark for more insight.
|
798
807
|
#
|
799
808
|
# ==== Juggling multiple LDAP connections
|
800
809
|
#
|
@@ -898,7 +907,7 @@ require 'activeldap/configuration'
|
|
898
907
|
require 'activeldap/schema2'
|
899
908
|
|
900
909
|
module ActiveLDAP
|
901
|
-
VERSION = "0.5.
|
910
|
+
VERSION = "0.5.4"
|
902
911
|
end
|
903
912
|
|
904
913
|
ActiveLDAP::Base.class_eval do
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-activeldap
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date:
|
6
|
+
version: 0.5.4
|
7
|
+
date: 2005-02-17
|
8
8
|
summary: Ruby/ActiveLDAP is a object-oriented API to LDAP
|
9
9
|
require_paths:
|
10
10
|
- lib
|