treequel 1.6.0 → 1.7.0
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/ChangeLog +163 -76
- data/History.rdoc +11 -0
- data/README.rdoc +14 -16
- data/Rakefile +6 -1
- data/bin/treequel +4 -10
- data/bin/treewhat +2 -4
- data/lib/treequel/branch.rb +49 -163
- data/lib/treequel/branchcollection.rb +11 -16
- data/lib/treequel/branchset.rb +24 -17
- data/lib/treequel/control.rb +8 -6
- data/lib/treequel/controls/contentsync.rb +2 -2
- data/lib/treequel/controls/pagedresults.rb +1 -10
- data/lib/treequel/directory.rb +36 -78
- data/lib/treequel/exceptions.rb +1 -2
- data/lib/treequel/filter.rb +3 -8
- data/lib/treequel/mixins.rb +2 -7
- data/lib/treequel/model/errors.rb +1 -4
- data/lib/treequel/model/objectclass.rb +14 -26
- data/lib/treequel/model.rb +18 -64
- data/lib/treequel/monkeypatches.rb +2 -3
- data/lib/treequel/schema/attributetype.rb +0 -5
- data/lib/treequel/schema/objectclass.rb +9 -27
- data/lib/treequel/schema.rb +1 -18
- data/lib/treequel/utils.rb +0 -3
- data/lib/treequel.rb +48 -75
- data/spec/treequel/branchset_spec.rb +24 -0
- data/spec/treequel/monkeypatches_spec.rb +9 -9
- data.tar.gz.sig +0 -0
- metadata +27 -27
- metadata.gz.sig +1 -3
@@ -16,7 +16,6 @@ module Treequel::Model::ObjectClass
|
|
16
16
|
|
17
17
|
|
18
18
|
### Extension callback -- add data structures to the extending +mod+.
|
19
|
-
### @param [Module] mod the mixin module to be extended
|
20
19
|
def self::extended( mod )
|
21
20
|
mod.instance_variable_set( :@model_class, Treequel::Model )
|
22
21
|
mod.instance_variable_set( :@model_objectclasses, [] )
|
@@ -65,11 +64,8 @@ module Treequel::Model::ObjectClass
|
|
65
64
|
|
66
65
|
|
67
66
|
### Set or get objectClasses that the mixin requires. Also registers the mixin with
|
68
|
-
### Treequel::Model.
|
69
|
-
###
|
70
|
-
### @param [Array<#to_sym>] objectclasses the objectClasses the mixin will apply to, as an
|
71
|
-
### array of Symbols (or objects that respond to #to_sym)
|
72
|
-
### @return [Array<Symbol>] the objectClasses that the module requires
|
67
|
+
### Treequel::Model. If +objectclasses+ are given, they are set as the objectClasses the
|
68
|
+
### mixin will apply to, as an array of Symbols (or objects that respond to #to_sym).
|
73
69
|
def model_objectclasses( *objectclasses )
|
74
70
|
unless objectclasses.empty?
|
75
71
|
@model_objectclasses = objectclasses.map( &:to_sym )
|
@@ -90,21 +86,18 @@ module Treequel::Model::ObjectClass
|
|
90
86
|
end
|
91
87
|
|
92
88
|
|
93
|
-
###
|
94
|
-
###
|
95
|
-
### directory
|
96
|
-
###
|
97
|
-
###
|
98
|
-
###
|
99
|
-
###
|
100
|
-
###
|
101
|
-
###
|
102
|
-
###
|
103
|
-
###
|
104
|
-
###
|
105
|
-
### @param [Treequel::Directory] directory the directory to create the entry in (optional)
|
106
|
-
### @param [#to_s] dn the DN of the new model object
|
107
|
-
### @param [Hash] entryhash attributes to set on the new entry
|
89
|
+
### :call-seq:
|
90
|
+
### ObjectClassModule.create( dn, entryhash={} )
|
91
|
+
### ObjectClassModule.create( directory, dn, entryhash={} )
|
92
|
+
###
|
93
|
+
### In the first form, creates a new instance of the mixin's model_class in the model_class's
|
94
|
+
### default directory with the given +dn+ and the objectclasses specified by the mixin.
|
95
|
+
###
|
96
|
+
### In the second form, creates a new instance of the mixin's model_class in the specified
|
97
|
+
### +directory+ with the given +dn+ and the objectclasses specified by the mixin.
|
98
|
+
###
|
99
|
+
### If the optional +entryhash+ is given (in either form), it will be used as the initial
|
100
|
+
### attributes of the new entry.
|
108
101
|
def create( directory, dn=nil, entryhash={} )
|
109
102
|
|
110
103
|
# Shift the arguments if the first one isn't a directory
|
@@ -136,11 +129,6 @@ module Treequel::Model::ObjectClass
|
|
136
129
|
### Return a Branchset (or BranchCollection if the receiver has more than one
|
137
130
|
### base) that can be used to search the given +directory+ for entries to which
|
138
131
|
### the receiver applies.
|
139
|
-
###
|
140
|
-
### @param [Treequel::Directory] directory the directory to search; if not given, this defaults
|
141
|
-
### to the directory associated with the module's
|
142
|
-
### model_class.
|
143
|
-
### @return [Treequel::Branchset, Treequel::BranchCollection] the encapsulated search
|
144
132
|
def search( directory=nil )
|
145
133
|
directory ||= self.model_class.directory
|
146
134
|
bases = self.model_bases
|
data/lib/treequel/model.rb
CHANGED
@@ -81,7 +81,6 @@ class Treequel::Model < Treequel::Branch
|
|
81
81
|
### Return the Treequel::Directory the Model will use for searches, creating it if it
|
82
82
|
### hasn't been created already. The default Directory will be created by calling
|
83
83
|
### Treequel.directory_from_config.
|
84
|
-
### @return [Treequel::Directory] the default directory
|
85
84
|
def self::directory
|
86
85
|
self.directory = Treequel.directory_from_config unless @directory
|
87
86
|
return @directory
|
@@ -90,7 +89,6 @@ class Treequel::Model < Treequel::Branch
|
|
90
89
|
|
91
90
|
### Set the Treequel::Directory that should be used for searches. The receiving class will also
|
92
91
|
### be set as the #results_class of the +newdirectory+.
|
93
|
-
### @param [Treequel::Directory] newdirectory
|
94
92
|
def self::directory=( newdirectory )
|
95
93
|
@directory = newdirectory
|
96
94
|
@directory.results_class = self if @directory
|
@@ -98,7 +96,6 @@ class Treequel::Model < Treequel::Branch
|
|
98
96
|
|
99
97
|
|
100
98
|
### Inheritance callback -- add a class-specific objectclass registry to inheriting classes.
|
101
|
-
### @param [Class] subclass the inheriting class
|
102
99
|
def self::inherited( subclass )
|
103
100
|
super
|
104
101
|
subclass.instance_variable_set( :@objectclass_registry, SET_HASH.dup )
|
@@ -107,10 +104,8 @@ class Treequel::Model < Treequel::Branch
|
|
107
104
|
|
108
105
|
|
109
106
|
### Register the given +mixin+ for the specified +objectclasses+. Instances that
|
110
|
-
### have all the specified +objectclasses+ will be extended with the +mixin
|
111
|
-
###
|
112
|
-
### @param [Module] mixin the mixin to be applied; it should be extended with
|
113
|
-
### Treequel::Model::ObjectClass.
|
107
|
+
### have all the specified +objectclasses+ will be extended with the +mixin+, which should be
|
108
|
+
### a Module extended with Treequel::Model::ObjectClass.
|
114
109
|
def self::register_mixin( mixin )
|
115
110
|
objectclasses = mixin.model_objectclasses
|
116
111
|
bases = mixin.model_bases
|
@@ -132,7 +127,6 @@ class Treequel::Model < Treequel::Branch
|
|
132
127
|
|
133
128
|
|
134
129
|
### Unregister the given +mixin+ for the specified +objectclasses+.
|
135
|
-
### @param [Module] mixin the mixin that should no longer be applied
|
136
130
|
def self::unregister_mixin( mixin )
|
137
131
|
objectclasses = mixin.model_objectclasses
|
138
132
|
bases = mixin.model_bases
|
@@ -154,8 +148,6 @@ class Treequel::Model < Treequel::Branch
|
|
154
148
|
|
155
149
|
|
156
150
|
### Return the mixins that should be applied to an entry with the given +objectclasses+.
|
157
|
-
### @param [Array<Symbol>] objectclasses the objectclasses from the entry
|
158
|
-
### @return [Set<Module>] the Set of mixin modules which apply
|
159
151
|
def self::mixins_for_objectclasses( *objectclasses )
|
160
152
|
return self.objectclass_registry[:top] if objectclasses.empty?
|
161
153
|
ocsymbols = objectclasses.flatten.collect {|oc| oc.untaint.to_sym }
|
@@ -174,8 +166,6 @@ class Treequel::Model < Treequel::Branch
|
|
174
166
|
|
175
167
|
|
176
168
|
### Return the mixins that should be applied to an entry with the given +dn+.
|
177
|
-
### @param [String] dn the DN of the entry
|
178
|
-
### @return [Set<Module>] the Set of mixin modules which apply
|
179
169
|
def self::mixins_for_dn( dn )
|
180
170
|
dn_tuples = dn.downcase.split( /\s*,\s*/ )
|
181
171
|
dn_keys = dn_tuples.reverse.inject(['']) do |keys, dnpair|
|
@@ -199,8 +189,6 @@ class Treequel::Model < Treequel::Branch
|
|
199
189
|
### Create a new Treequel::Model object with the given +entry+ hash from the
|
200
190
|
### specified +directory+. Overrides Treequel::Branch.new_from_entry to pass the
|
201
191
|
### +from_directory+ flag to mark it as unmodified.
|
202
|
-
###
|
203
|
-
### @see Treequel::Branch.new_from_entry
|
204
192
|
def self::new_from_entry( entry, directory )
|
205
193
|
entry = Treequel::HashUtilities.stringify_keys( entry )
|
206
194
|
dnvals = entry.delete( 'dn' ) or
|
@@ -269,17 +257,18 @@ class Treequel::Model < Treequel::Branch
|
|
269
257
|
|
270
258
|
### Index set operator -- set attribute +attrname+ to a new +value+.
|
271
259
|
### Overridden to make Model objects defer writing changes until
|
272
|
-
###
|
273
|
-
###
|
274
|
-
### @param [Symbol, String] attrname attribute name
|
275
|
-
### @param [Object] value the attribute value
|
260
|
+
### Treequel::Model#save is called.
|
276
261
|
def []=( attrname, value )
|
277
262
|
attrtype = self.find_attribute_type( attrname.to_sym ) or
|
278
263
|
raise ArgumentError, "unknown attribute %p" % [ attrname ]
|
279
264
|
value = Array( value ) unless attrtype.single?
|
280
265
|
|
281
266
|
self.mark_dirty
|
282
|
-
|
267
|
+
if value
|
268
|
+
@values[ attrtype.name.to_sym ] = value
|
269
|
+
else
|
270
|
+
@values.delete( attrtype.name.to_sym )
|
271
|
+
end
|
283
272
|
|
284
273
|
# If the objectClasses change, we (may) need to re-apply mixins
|
285
274
|
if attrname.to_s.downcase == 'objectclass'
|
@@ -295,10 +284,7 @@ class Treequel::Model < Treequel::Branch
|
|
295
284
|
|
296
285
|
### Make the changes to the object specified by the given +attributes+.
|
297
286
|
### Overridden to make Model objects defer writing changes until
|
298
|
-
###
|
299
|
-
###
|
300
|
-
### @param attributes (see Treequel::Directory#modify)
|
301
|
-
### @return [TrueClass] if the merge succeeded
|
287
|
+
### Treequel::Model#save is called.
|
302
288
|
def merge( attributes )
|
303
289
|
attributes.each do |attrname, value|
|
304
290
|
self[ attrname ] = value
|
@@ -308,9 +294,7 @@ class Treequel::Model < Treequel::Branch
|
|
308
294
|
|
309
295
|
### Delete the specified attributes.
|
310
296
|
### Overridden to make Model objects defer writing changes until
|
311
|
-
###
|
312
|
-
###
|
313
|
-
### @see Treequel::Branch#delete
|
297
|
+
### Treequel::Model#save is called.
|
314
298
|
def delete( *attributes )
|
315
299
|
return super if attributes.empty?
|
316
300
|
|
@@ -344,7 +328,6 @@ class Treequel::Model < Treequel::Branch
|
|
344
328
|
|
345
329
|
|
346
330
|
### Returns the validation errors associated with this object.
|
347
|
-
### @see Treequel::Model::Errors.
|
348
331
|
def errors
|
349
332
|
return @errors ||= Treequel::Model::Errors.new
|
350
333
|
end
|
@@ -360,8 +343,6 @@ class Treequel::Model < Treequel::Branch
|
|
360
343
|
|
361
344
|
### Validate the object with the specified +options+. Appending validation errors onto
|
362
345
|
### the #errors object.
|
363
|
-
### @param [Hash] options options for validation.
|
364
|
-
### @option options [Boolean] :with_schema whether or not to run the schema validations
|
365
346
|
def validate( options={} )
|
366
347
|
options = DEFAULT_VALIDATION_OPTIONS.merge( options )
|
367
348
|
|
@@ -377,10 +358,11 @@ class Treequel::Model < Treequel::Branch
|
|
377
358
|
end
|
378
359
|
|
379
360
|
|
380
|
-
### Write any pending changes in the model object to the directory.
|
381
|
-
###
|
382
|
-
###
|
383
|
-
###
|
361
|
+
### Write any pending changes in the model object to the directory. The valid +opts+ are:
|
362
|
+
###
|
363
|
+
### [+:raise_on_failure+]
|
364
|
+
### raise a Treequel::ValidationFailed or Treequel::BeforeHookFailed if either the
|
365
|
+
### validations or before_{save,create}.
|
384
366
|
def save( opts={} )
|
385
367
|
opts = DEFAULT_SAVE_OPTIONS.merge( opts )
|
386
368
|
|
@@ -418,8 +400,7 @@ class Treequel::Model < Treequel::Branch
|
|
418
400
|
end
|
419
401
|
|
420
402
|
|
421
|
-
### Return any pending changes in the model object.
|
422
|
-
### @return [Array<LDAP::Mod>] the changes as LDAP modifications
|
403
|
+
### Return any pending changes in the model object as an Array of LDAP::Mod objects.
|
423
404
|
def modifications
|
424
405
|
return unless self.modified?
|
425
406
|
self.log.debug "Gathering modifications..."
|
@@ -508,8 +489,6 @@ class Treequel::Model < Treequel::Branch
|
|
508
489
|
|
509
490
|
|
510
491
|
### Returns +true+ if the receiver responds to the given method.
|
511
|
-
### @param [Symbol,String] sym the name of the method to test for
|
512
|
-
### @return [Boolean]
|
513
492
|
def respond_to?( sym, include_priv=false )
|
514
493
|
return super if caller(1).first =~ %r{/r?spec/} &&
|
515
494
|
caller(1).first !~ /respond_to/ # RSpec workaround
|
@@ -520,7 +499,6 @@ class Treequel::Model < Treequel::Branch
|
|
520
499
|
|
521
500
|
|
522
501
|
### Return the Treequel::Model::ObjectClass mixins that have been applied to the receiver.
|
523
|
-
### @return [Array<Module>]
|
524
502
|
def extensions
|
525
503
|
eigenclass = ( class << self; self; end )
|
526
504
|
return eigenclass.included_modules.find_all do |mod|
|
@@ -554,7 +532,6 @@ class Treequel::Model < Treequel::Branch
|
|
554
532
|
|
555
533
|
|
556
534
|
### Update the object's entry with the specified +mods+.
|
557
|
-
### @param [Array<LDAP::Mod>] mods the modifications to make
|
558
535
|
def update( mods )
|
559
536
|
self.log.debug " entry already exists: updating..."
|
560
537
|
self.before_update( mods ) or
|
@@ -565,7 +542,6 @@ class Treequel::Model < Treequel::Branch
|
|
565
542
|
|
566
543
|
|
567
544
|
### Create the entry for the object, using the specified +mods+ to set the attributes.
|
568
|
-
### @param [Array<LDAP::Mod>] mods the modifications to set attributes
|
569
545
|
def create( mods )
|
570
546
|
self.log.debug " entry doesn't exist: creating..."
|
571
547
|
self.before_create( mods ) or
|
@@ -576,7 +552,6 @@ class Treequel::Model < Treequel::Branch
|
|
576
552
|
|
577
553
|
|
578
554
|
### Delete specific key/value +pairs+ from the entry.
|
579
|
-
### @param [Hash] pairs key/value pairs to delete from the entry.
|
580
555
|
def delete_specific_values( pairs )
|
581
556
|
self.log.debug " hash-delete..."
|
582
557
|
|
@@ -592,10 +567,6 @@ class Treequel::Model < Treequel::Branch
|
|
592
567
|
|
593
568
|
|
594
569
|
### Search for the Treequel::Schema::AttributeType associated with +sym+.
|
595
|
-
###
|
596
|
-
### @param [Symbol,String] name the name of the attribute to find
|
597
|
-
### @return [Treequel::Schema::AttributeType,nil] the associated attributeType, or nil
|
598
|
-
### if there isn't one
|
599
570
|
def find_attribute_type( name )
|
600
571
|
attrtype = nil
|
601
572
|
|
@@ -627,17 +598,15 @@ class Treequel::Model < Treequel::Branch
|
|
627
598
|
return meth.call( *args ) if meth
|
628
599
|
end
|
629
600
|
|
630
|
-
self.log.debug " checking to see if it's a traversal call"
|
601
|
+
# self.log.debug " checking to see if it's a traversal call"
|
602
|
+
|
631
603
|
# Next, super to rdn-traversal if it looks like a reader but has arguments
|
632
604
|
plainsym, methodtype = attribute_from_method( sym )
|
633
|
-
self.log.debug " method looks like a %p" % [ methodtype ]
|
634
605
|
return super if methodtype == :reader && !args.empty?
|
635
|
-
self.log.debug " ...but it doesn't have any arguments. Finding attr type."
|
636
606
|
|
637
607
|
# Now make a method body for a new method based on what attributeType it is if
|
638
608
|
# it's a valid attribute
|
639
609
|
attrtype = self.find_attribute_type( plainsym ) or return super
|
640
|
-
self.log.debug " attrtype is: %p" % [ attrtype ]
|
641
610
|
methodbody = case methodtype
|
642
611
|
when :writer
|
643
612
|
self.make_writer( attrtype )
|
@@ -655,10 +624,6 @@ class Treequel::Model < Treequel::Branch
|
|
655
624
|
|
656
625
|
|
657
626
|
### Make a reader method body for the given +attrtype+.
|
658
|
-
###
|
659
|
-
### @param [Treequel::Mode::AttributeType] attrtype the attributeType to create the reader
|
660
|
-
### for.
|
661
|
-
### @return [Proc] the body of the reader method.
|
662
627
|
def make_reader( attrtype )
|
663
628
|
self.log.debug "Generating an attribute reader for %p" % [ attrtype ]
|
664
629
|
attrname = attrtype.name
|
@@ -673,10 +638,6 @@ class Treequel::Model < Treequel::Branch
|
|
673
638
|
|
674
639
|
|
675
640
|
### Make a writer method body for the given +attrtype+.
|
676
|
-
###
|
677
|
-
### @param [Treequel::Mode::AttributeType] attrtype the attributeType to create the accessor
|
678
|
-
### for.
|
679
|
-
### @return [Proc] the body of the writer method.
|
680
641
|
def make_writer( attrtype )
|
681
642
|
self.log.debug "Generating an attribute writer for %p" % [ attrtype ]
|
682
643
|
attrname = attrtype.name
|
@@ -691,10 +652,6 @@ class Treequel::Model < Treequel::Branch
|
|
691
652
|
|
692
653
|
|
693
654
|
### Make a predicate method body for the given +attrtype+.
|
694
|
-
###
|
695
|
-
### @param [Treequel::Mode::AttributeType] attrtype the attributeType to create the method
|
696
|
-
### for.
|
697
|
-
### @return [Proc] the body of the predicate method.
|
698
655
|
def make_predicate( attrtype )
|
699
656
|
self.log.debug "Generating an attribute predicate for %p" % [ attrtype ]
|
700
657
|
attrname = attrtype.name
|
@@ -710,7 +667,6 @@ class Treequel::Model < Treequel::Branch
|
|
710
667
|
|
711
668
|
### Overridden to apply applicable mixins to lazily-loaded objects once their entry
|
712
669
|
### has been looked up.
|
713
|
-
### @return [LDAP::Entry] the fetched entry object
|
714
670
|
def lookup_entry
|
715
671
|
if entryhash = super
|
716
672
|
self.apply_applicable_mixins( self.dn, entryhash )
|
@@ -754,8 +710,6 @@ class Treequel::Model < Treequel::Branch
|
|
754
710
|
|
755
711
|
### Given the symbol from an attribute accessor or predicate, return the
|
756
712
|
### name of the corresponding LDAP attribute/
|
757
|
-
### @param [Symbol] methodname the method being called
|
758
|
-
### @return [Symbol] the attribute name that corresponds to the method
|
759
713
|
def attribute_from_method( methodname )
|
760
714
|
|
761
715
|
case methodname.to_s
|
@@ -25,7 +25,6 @@ end # module Treequel::LDAPControlExtensions
|
|
25
25
|
|
26
26
|
|
27
27
|
# Include Treequel-specific extensions as a mixin.
|
28
|
-
# @private
|
29
28
|
class LDAP::Control
|
30
29
|
include Treequel::LDAPControlExtensions
|
31
30
|
end
|
@@ -46,7 +45,6 @@ end # module Treequel::LDAPModExtensions
|
|
46
45
|
|
47
46
|
|
48
47
|
# Include Treequel-specific extensions as a mixin.
|
49
|
-
# @private
|
50
48
|
class LDAP::Mod
|
51
49
|
include Treequel::LDAPModExtensions
|
52
50
|
|
@@ -71,7 +69,8 @@ class LDAP::Mod
|
|
71
69
|
|
72
70
|
### Override the initializer to keep the +attribute+ around while the object
|
73
71
|
### is alive to prevent the underlying C String pointer from going away.
|
74
|
-
###
|
72
|
+
###
|
73
|
+
### See line 151 of mod.c.
|
75
74
|
def initialize( op, attribute, vals )
|
76
75
|
@attribute = attribute
|
77
76
|
_initialize_ext( op, attribute, vals )
|
@@ -330,7 +330,6 @@ class Treequel::Schema::AttributeType
|
|
330
330
|
# attributes.
|
331
331
|
|
332
332
|
### Test whether or not the attrinbute is a user applications attribute.
|
333
|
-
### @return [Boolean] true if the attribute's USAGE is 'userApplications' (or nil)
|
334
333
|
def is_user?
|
335
334
|
return !self.is_operational?
|
336
335
|
end
|
@@ -338,7 +337,6 @@ class Treequel::Schema::AttributeType
|
|
338
337
|
|
339
338
|
|
340
339
|
### Test whether or not the attribute is an operational attribute.
|
341
|
-
### @return [Boolean] true if the attribute's usage is one of the OPERATIONAL_ATTRIBUTE_USAGES
|
342
340
|
def is_operational?
|
343
341
|
usage_type = self.usage || DEFAULT_USAGE_TYPE
|
344
342
|
return OPERATIONAL_ATTRIBUTE_USAGES.map( &:downcase ).include?( usage_type.downcase )
|
@@ -347,7 +345,6 @@ class Treequel::Schema::AttributeType
|
|
347
345
|
|
348
346
|
|
349
347
|
### Test whether or not the attribute is a directory operational attribute.
|
350
|
-
### @return [Boolean] true if the attribute's usage is 'directoryOperation'
|
351
348
|
def is_directory_operational?
|
352
349
|
usage_type = self.usage || DEFAULT_USAGE_TYPE
|
353
350
|
return usage_type == 'directoryOperation'
|
@@ -356,7 +353,6 @@ class Treequel::Schema::AttributeType
|
|
356
353
|
|
357
354
|
|
358
355
|
### Test whether or not the attribute is a distributed operational attribute.
|
359
|
-
### @return [Boolean] true if the attribute's usage is 'distributedOperation'
|
360
356
|
def is_distributed_operational?
|
361
357
|
usage_type = self.usage || DEFAULT_USAGE_TYPE
|
362
358
|
return usage_type == 'distributedOperation'
|
@@ -365,7 +361,6 @@ class Treequel::Schema::AttributeType
|
|
365
361
|
|
366
362
|
|
367
363
|
### Test whether or not the attribute is a DSA-specific operational attribute.
|
368
|
-
### @return [Boolean] true if the attribute's usage is 'dSAOperation'
|
369
364
|
def is_dsa_operational?
|
370
365
|
usage_type = self.usage || DEFAULT_USAGE_TYPE
|
371
366
|
return usage_type == 'dSAOperation'
|
@@ -52,10 +52,8 @@ class Treequel::Schema
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
### Parse an ObjectClass entry from a objectClass +description+ from a
|
56
|
-
###
|
57
|
-
### @param [Treequel::Schema] schema the schema object the objectClass belongs to
|
58
|
-
### @return [Treequel::Schema::ObjectClass] the resulting objectclass
|
55
|
+
### Parse an ObjectClass entry from a RFC4512-format objectClass +description+ from a
|
56
|
+
### +schema+.
|
59
57
|
def self::parse( schema, description )
|
60
58
|
oid, names, desc, obsolete, sup, kind, must, may, extensions = nil
|
61
59
|
|
@@ -166,10 +164,8 @@ class Treequel::Schema
|
|
166
164
|
|
167
165
|
|
168
166
|
### Return the objectClass's MUST OIDs as Symbols (for symbolic OIDs) or Strings (for
|
169
|
-
### dotted-numeric OIDs).
|
170
|
-
###
|
171
|
-
### objectClass's SUP, if it has one.
|
172
|
-
### @return [Array<Symbol,String>] the objectClass's MUST OIDs
|
167
|
+
### dotted-numeric OIDs). If include_sup is true, include MUST OIDs inherited from the
|
168
|
+
### objectClass's SUP, if it has one.
|
173
169
|
def must_oids( include_sup=true )
|
174
170
|
oids = @must_oids.dup
|
175
171
|
|
@@ -193,10 +189,8 @@ class Treequel::Schema
|
|
193
189
|
|
194
190
|
|
195
191
|
### Return the objectClass's MAY OIDs as Symbols (for symbolic OIDs) or Strings (for
|
196
|
-
### dotted-numeric OIDs).
|
197
|
-
###
|
198
|
-
### objectClass's SUP, if it has one.
|
199
|
-
### @return [Array<Symbol,String>] the objectClass's MAY OIDs
|
192
|
+
### dotted-numeric OIDs). If include_sup is true, include MAY OIDs inherited from the
|
193
|
+
### objectClass's SUP, if it has one.
|
200
194
|
def may_oids( include_sup=true )
|
201
195
|
oids = @may_oids.dup
|
202
196
|
|
@@ -258,15 +252,6 @@ class Treequel::Schema
|
|
258
252
|
return "( %s )" % [ parts.join(' ') ]
|
259
253
|
end
|
260
254
|
|
261
|
-
# @oid = oid
|
262
|
-
# @names = names
|
263
|
-
# @desc = desc
|
264
|
-
# @obsolete = obsolete ? true : false
|
265
|
-
# @sup_oid = sup
|
266
|
-
# @must_oids = must_oids
|
267
|
-
# @may_oids = may_oids
|
268
|
-
# @extensions = extensions
|
269
|
-
|
270
255
|
|
271
256
|
### Return a human-readable representation of the object suitable for debugging
|
272
257
|
def inspect
|
@@ -295,9 +280,7 @@ class Treequel::Schema
|
|
295
280
|
|
296
281
|
|
297
282
|
### Return the SUP chain for the receiver up to 'top', including the receiver
|
298
|
-
### itself.
|
299
|
-
### @return [Array<Treequel::Schema::ObjectClass>] the array of ObjectClass objects
|
300
|
-
### the receiver inherits from.
|
283
|
+
### itself, as an Array of Treequel::Schema::ObjectClass objects.
|
301
284
|
def ancestors
|
302
285
|
rval = [ self ]
|
303
286
|
|
@@ -309,9 +292,8 @@ class Treequel::Schema
|
|
309
292
|
end
|
310
293
|
|
311
294
|
|
312
|
-
### Return the string that represents the kind of objectClass
|
313
|
-
###
|
314
|
-
### @return [String] one of: 'ABSTRACT', 'STRUCTURAL', 'AUXILIARY'
|
295
|
+
### Return the string that represents the kind of objectClass the receiver represents.
|
296
|
+
### It will be one of: 'ABSTRACT', 'STRUCTURAL', 'AUXILIARY'
|
315
297
|
def kind
|
316
298
|
return Treequel::Schema::OBJECTCLASS_TYPES.invert[ self.class ]
|
317
299
|
end
|
data/lib/treequel/schema.rb
CHANGED
@@ -42,14 +42,12 @@ class Treequel::Schema
|
|
42
42
|
### Set the strict-parsing +flag+. Setting this to a +true+ value causes schema-parsing
|
43
43
|
### errors to be propagated to the caller instead of handled by the constructor, which is
|
44
44
|
### the default behavior.
|
45
|
-
### @param [boolean] flag the new flag value
|
46
45
|
def self::strict_parse_mode=( newval )
|
47
46
|
@strict_parse_mode = newval ? true : false
|
48
47
|
end
|
49
48
|
|
50
49
|
|
51
50
|
### Test whether or not strict-parsing mode is in effect.
|
52
|
-
### @return [boolean] false if parse errors will be caught
|
53
51
|
def self::strict_parse_mode?
|
54
52
|
return @strict_parse_mode ? true : false
|
55
53
|
end
|
@@ -125,8 +123,6 @@ class Treequel::Schema
|
|
125
123
|
|
126
124
|
### Return a description of the given +descriptors+ suitable for inclusion in
|
127
125
|
### an RFC4512-style schema description entry.
|
128
|
-
### @param [Array<String>] descriptors an Array of descriptors
|
129
|
-
### @return [String] the 'qdescrs' text
|
130
126
|
def self::qdescrs( *descriptors )
|
131
127
|
descriptors.flatten!
|
132
128
|
if descriptors.length > 1
|
@@ -149,8 +145,6 @@ class Treequel::Schema
|
|
149
145
|
|
150
146
|
### Escape and quote the specified +string+ according to the rules in
|
151
147
|
### RFC4512/2252.
|
152
|
-
### @param [String] string the unescaped UTF8 string
|
153
|
-
### @return [String] the string after quoting and escaping
|
154
148
|
def self::qdstring( string )
|
155
149
|
return "'%s'" % [ string.to_s.gsub(/\\/, '\\\\5c').gsub(/'/, '\\\\27') ]
|
156
150
|
end
|
@@ -158,8 +152,6 @@ class Treequel::Schema
|
|
158
152
|
|
159
153
|
### Return a description of the given +oids+ suitable for inclusion in
|
160
154
|
### an RFC4512-style schema description entry.
|
161
|
-
### @param [Array<String>] oids an Array of numeric or symbolic OIDs
|
162
|
-
### @return [String] the oid list text
|
163
155
|
def self::oids( *oids )
|
164
156
|
oids.flatten!
|
165
157
|
if oids.length > 1
|
@@ -194,34 +186,28 @@ class Treequel::Schema
|
|
194
186
|
|
195
187
|
# The table of Treequel::Schema::ObjectClass objects, keyed by OID and any associated NAME
|
196
188
|
# attributes (as Symbols), that describes the objectClasses in the directory's schema.
|
197
|
-
# @return [Treequel::Schema::Table]
|
198
189
|
attr_reader :object_classes
|
199
190
|
|
200
191
|
# The hash of Treequel::Schema::AttributeType objects, keyed by OID and any associated NAME
|
201
192
|
# attributes (as Symbols), that describe the attributeTypes in the directory's schema.
|
202
|
-
# @return [Treequel::Schema::Table]
|
203
193
|
attr_reader :attribute_types
|
204
194
|
|
205
195
|
# The hash of Treequel::Schema::LDAPSyntax objects, keyed by OID, that describe the
|
206
196
|
# syntaxes in the directory's schema.
|
207
|
-
# @return [Treequel::Schema::Table]
|
208
197
|
attr_reader :ldap_syntaxes
|
209
198
|
|
210
199
|
# The hash of Treequel::Schema::MatchingRule objects, keyed by OID and any associated NAME
|
211
200
|
# attributes (as Symbols), that describe the matchingRules int he directory's schema.
|
212
|
-
# @return [Treequel::Schema::Table]
|
213
201
|
attr_reader :matching_rules
|
214
202
|
|
215
203
|
# The hash of Treequel::Schema::MatchingRuleUse objects, keyed by OID and any associated NAME
|
216
204
|
# attributes (as Symbols), that describe the attributes to which a matchingRule can be applied.
|
217
|
-
# @return [Treequel::Schema::Table]
|
218
205
|
attr_reader :matching_rule_uses
|
219
206
|
alias_method :matching_rule_use, :matching_rule_uses
|
220
207
|
|
221
208
|
|
222
209
|
### Return the Treequel::Schema::AttributeType objects that correspond to the
|
223
210
|
### operational attributes that are supported by the directory.
|
224
|
-
### @return [Array<Treequel::Schema::AttributeType>] the operational attributes
|
225
211
|
def operational_attribute_types
|
226
212
|
return self.attribute_types.values.find_all {|attrtype| attrtype.operational? }.uniq
|
227
213
|
end
|
@@ -236,7 +222,6 @@ class Treequel::Schema
|
|
236
222
|
|
237
223
|
|
238
224
|
### Return a human-readable representation of the object suitable for debugging.
|
239
|
-
### @return [String]
|
240
225
|
def inspect
|
241
226
|
return %{#<%s:0x%0x %s>} % [
|
242
227
|
self.class.name,
|
@@ -361,9 +346,7 @@ class Treequel::Schema
|
|
361
346
|
end
|
362
347
|
|
363
348
|
|
364
|
-
### Return descriptions of the schema's artifacts.
|
365
|
-
### @return [Array<String>] the descriptions of the schema's artifacts, and how many of each
|
366
|
-
### it has.
|
349
|
+
### Return descriptions of the schema's artifacts, and how many of each it has.
|
367
350
|
def ivar_descriptions
|
368
351
|
self.instance_variables.sort.collect do |ivar|
|
369
352
|
len = self.instance_variable_get( ivar ).length
|
data/lib/treequel/utils.rb
CHANGED
@@ -12,7 +12,6 @@ require 'treequel/mixins'
|
|
12
12
|
module Treequel
|
13
13
|
|
14
14
|
# A alternate formatter for Logger instances.
|
15
|
-
# @private
|
16
15
|
class LogFormatter < Logger::Formatter
|
17
16
|
|
18
17
|
# The format to output unless debugging is turned on
|
@@ -68,7 +67,6 @@ module Treequel
|
|
68
67
|
|
69
68
|
|
70
69
|
# A ANSI-colorized formatter for Logger instances.
|
71
|
-
# @private
|
72
70
|
class ColorLogFormatter < Logger::Formatter
|
73
71
|
extend Treequel::ANSIColorUtilities
|
74
72
|
|
@@ -122,7 +120,6 @@ module Treequel
|
|
122
120
|
|
123
121
|
# An alternate formatter for Logger instances that outputs +div+ HTML
|
124
122
|
# fragments.
|
125
|
-
# @private
|
126
123
|
class HtmlLogFormatter < Logger::Formatter
|
127
124
|
include ERB::Util # for html_escape()
|
128
125
|
|