treequel 1.8.6 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,8 +1,43 @@
1
+ 2012-05-22 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * .rvm.gems, .tm_properties, README.rdoc, lib/treequel.rb,
4
+ lib/treequel/branch.rb, lib/treequel/branchcollection.rb,
5
+ lib/treequel/branchset.rb, lib/treequel/directory.rb,
6
+ lib/treequel/filter.rb, lib/treequel/mixins.rb,
7
+ lib/treequel/model.rb, lib/treequel/model/errors.rb,
8
+ lib/treequel/schema.rb, lib/treequel/schema/attributetype.rb,
9
+ lib/treequel/schema/ldapsyntax.rb,
10
+ lib/treequel/schema/matchingrule.rb,
11
+ lib/treequel/schema/matchingruleuse.rb,
12
+ lib/treequel/schema/objectclass.rb, lib/treequel/schema/table.rb,
13
+ spec/lib/helpers.rb, spec/treequel/directory_spec.rb,
14
+ spec/treequel/mixins_spec.rb, spec/treequel_spec.rb:
15
+ Convert to Loggability for logging
16
+ [2e32ed84d899] [tip]
17
+
18
+ 2012-04-16 Michael Granger <ged@FaerieMUD.org>
19
+
20
+ * README.rdoc, Rakefile:
21
+ Update README, use Fivefish if available.
22
+ [4dcbdee767aa]
23
+
1
24
  2012-03-20 Michael Granger <ged@FaerieMUD.org>
2
25
 
26
+ * .hgtags:
27
+ Added tag v1.8.6 for changeset 85858da99269
28
+ [e1a894f09484]
29
+
30
+ * .hgsigs:
31
+ Added signature for changeset 4b71de99d5fd
32
+ [85858da99269] [v1.8.6]
33
+
34
+ * History.rdoc, Rakefile, lib/treequel.rb:
35
+ Bump the patch version, update History.
36
+ [4b71de99d5fd]
37
+
3
38
  * experiments/spec-profile-r408f5fadc4c5.graffle:
4
39
  Add spec profile
5
- [654ba9e47642] [github/master, tip]
40
+ [654ba9e47642] [github/master]
6
41
 
7
42
  * .hgignore, Manifest.txt, Rakefile, lib/treequel/constants.rb,
8
43
  lib/treequel/directory.rb, spec/lib/helpers.rb,
data/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == v1.9.0 [2012-06-06] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Convert to Loggability for logging
4
+ - Update README, use Fivefish if available.
5
+
6
+
1
7
  == v1.8.6 [2012-03-20] Michael Granger <ged@FaerieMUD.org>
2
8
 
3
9
  - Fix encoding of directory strings under Ruby 1.9 and newer versions
data/Manifest.txt CHANGED
@@ -39,7 +39,6 @@ lib/treequel/schema/matchingruleuse.rb
39
39
  lib/treequel/schema/objectclass.rb
40
40
  lib/treequel/schema/table.rb
41
41
  lib/treequel/sequel_integration.rb
42
- lib/treequel/utils.rb
43
42
  spec/data/ad_schema.yml
44
43
  spec/data/objectClasses.yml
45
44
  spec/data/opends.yml
data/README.rdoc CHANGED
@@ -1,19 +1,21 @@
1
- = Treequel - an honest LDAP library
1
+ = Treequel
2
+
3
+ home :: http://deveiate.org/projects/Treequel
4
+ code :: http://repo.deveiate.org/Treequel
5
+ docs :: http://deveiate.org/code/treequel
6
+ github :: http://github.com/ged/treequel
2
7
 
3
- * http://deveiate.org/projects/Treequel
4
8
 
5
9
  == Description
6
10
 
7
11
  Treequel is an LDAP toolkit for Ruby. It is intended to allow quick, easy
8
12
  access to LDAP directories in a manner consistent with LDAP's hierarchical,
9
- free-form nature.
13
+ free-form nature.
10
14
 
11
15
  It's inspired by and modeled after {Sequel}[http://sequel.rubyforge.org/], a
12
16
  kick-ass database library.
13
17
 
14
18
 
15
-
16
-
17
19
  == Contributing
18
20
 
19
21
  You can check out the current development source
@@ -27,7 +29,7 @@ You can submit bug reports, suggestions, and read more about future plans at
27
29
 
28
30
  == License
29
31
 
30
- Copyright (c) 2008-2011, Michael Granger and Mahlon E. Smith
32
+ Copyright (c) 2008-2012, Michael Granger and Mahlon E. Smith
31
33
  All rights reserved.
32
34
 
33
35
  Redistribution and use in source and binary forms, with or without
@@ -55,7 +57,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55
57
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56
58
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57
59
 
58
- This software includes some code from the Sequel database toolkit, used under
60
+ This software includes some code from the Sequel database toolkit, used under
59
61
  the following license terms:
60
62
 
61
63
  Copyright (c) 2007-2008 Sharon Rosner
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ hoespec = Hoe.spec 'treequel' do
19
19
  self.readme_file = 'README.rdoc'
20
20
  self.history_file = 'History.rdoc'
21
21
  self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
22
+ self.spec_extras[:rdoc_options] = ['-f', 'fivefish', '-t', 'Treequel']
22
23
 
23
24
  self.need_tar = true
24
25
  self.need_zip = true
@@ -31,6 +32,8 @@ hoespec = Hoe.spec 'treequel' do
31
32
  else
32
33
  self.dependency 'ruby-ldap', '~> 0.9'
33
34
  end
35
+ self.dependency 'loggability', '~> 0.4'
36
+
34
37
  self.dependency 'rspec', '~> 2.8', :developer
35
38
  self.dependency 'ruby-termios', '~> 0.9', :developer
36
39
  self.dependency 'ruby-terminfo', '~> 0.1', :developer
data/lib/treequel.rb CHANGED
@@ -4,7 +4,7 @@ require 'ldap'
4
4
  require 'ldap/schema'
5
5
  require 'ldap/control'
6
6
 
7
- require 'logger'
7
+ require 'loggability'
8
8
  require 'pathname'
9
9
 
10
10
  require 'uri'
@@ -24,12 +24,18 @@ end
24
24
 
25
25
  # A library for interacting with LDAP modelled after Sequel[http://sequel.rubyforge.org/].
26
26
  module Treequel
27
+ extend Loggability
28
+
29
+
30
+ # Loggability API -- set up a Logger for all Treequel-related logging
31
+ log_as :treequel
32
+
27
33
 
28
34
  # Library version
29
- VERSION = '1.8.6'
35
+ VERSION = '1.9.0'
30
36
 
31
37
  # VCS revision
32
- REVISION = %q$Revision: 4b71de99d5fd $
38
+ REVISION = %q$Revision: 29134510ef85 $
33
39
 
34
40
  # Common paths for ldap.conf
35
41
  COMMON_LDAP_CONF_PATHS = %w[
@@ -60,58 +66,6 @@ module Treequel
60
66
  end
61
67
 
62
68
 
63
- #
64
- # :section: Logging
65
- #
66
-
67
- # Log levels
68
- LOG_LEVELS = {
69
- 'debug' => Logger::DEBUG,
70
- 'info' => Logger::INFO,
71
- 'warn' => Logger::WARN,
72
- 'error' => Logger::ERROR,
73
- 'fatal' => Logger::FATAL,
74
- }.freeze
75
- LOG_LEVEL_NAMES = LOG_LEVELS.invert.freeze
76
-
77
- @default_logger = Logger.new( $stderr )
78
- @default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
79
-
80
- @default_log_formatter = Treequel::LogFormatter.new( @default_logger )
81
- @default_logger.formatter = @default_log_formatter
82
-
83
- @logger = @default_logger
84
-
85
-
86
- class << self
87
- # The log formatter that will be used when the logging subsystem is reset
88
- attr_accessor :default_log_formatter
89
-
90
- # The logger that will be used when the logging subsystem is reset
91
- attr_accessor :default_logger
92
-
93
- # The logger that's currently in effect
94
- attr_accessor :logger
95
- alias_method :log, :logger
96
- alias_method :log=, :logger=
97
- end
98
-
99
-
100
- ### Reset the global logger object to the default
101
- def self::reset_logger
102
- self.logger = self.default_logger
103
- self.logger.level = Logger::WARN
104
- self.logger.formatter = self.default_log_formatter
105
- end
106
-
107
-
108
- ### Returns +true+ if the global logger has not been set to something other than
109
- ### the default one.
110
- def self::using_default_logger?
111
- return self.logger == self.default_logger
112
- end
113
-
114
-
115
69
  #
116
70
  # :section:
117
71
  #
@@ -318,6 +272,22 @@ module Treequel
318
272
  end
319
273
 
320
274
 
275
+ ### Reset the logger associated with Treequel. Backward-compatibility method.
276
+ def self::reset_logger
277
+ Treequel.logger = Treequel.default_logger
278
+ Treequel.logger.formatter = nil
279
+ Treequel.logger.output_to( $stderr )
280
+ Treequel.logger.level = :fatal
281
+ end
282
+
283
+
284
+ ### Returns +true+ if the current logger for Treequel is the default one.
285
+ ### Backward-compatibility method.
286
+ def self::using_default_logger?
287
+ return Loggability[ Treequel ] == Treequel.default_logger
288
+ end
289
+
290
+
321
291
  # Now load the rest of the library
322
292
  require 'treequel/exceptions'
323
293
  require 'treequel/directory'
@@ -15,15 +15,19 @@ require 'treequel/branchcollection'
15
15
  # for the entries below itself, and how to search for those entries.
16
16
  class Treequel::Branch
17
17
  include Comparable,
18
- Treequel::Loggable,
19
18
  Treequel::Constants,
20
19
  Treequel::Constants::Patterns,
21
20
  Treequel::HashUtilities
22
21
 
23
- extend Treequel::Delegation,
22
+ extend Loggability,
23
+ Treequel::Delegation,
24
24
  Treequel::AttributeDeclarations
25
25
 
26
26
 
27
+ # Loggability API -- Log to the Treequel module's logger
28
+ log_to :treequel
29
+
30
+
27
31
  # The default width of LDIF output
28
32
  DEFAULT_LDIF_WIDTH = 70
29
33
 
@@ -12,29 +12,33 @@ require 'treequel/branch'
12
12
  # A Treequel::BranchCollection is a union of Treequel::Branchset
13
13
  # objects, suitable for performing operations on multiple branches
14
14
  # of the directory at once.
15
- #
15
+ #
16
16
  # For example, if you have hosts under ou=Hosts in two different
17
17
  # subdomains (e.g., acme.com, seattle.acme.com, and newyork.acme.com),
18
18
  # and you want to search for a host by its CN, you could do so like
19
19
  # this:
20
- #
20
+ #
21
21
  # # Top-level hosts, and those in the 'seattle' subdomain, but not
22
22
  # # those in the 'newyork' subdomain:
23
23
  # west_coast_hosts = dir.ou( :hosts ) + dir.dc( :seattle ).ou( :hosts )
24
24
  # west_coast_www_hosts = west_coast_hosts.filter( :cn => 'www' )
25
- #
25
+ #
26
26
  # # And one that includes hosts in all three DCs:
27
27
  # all_hosts = west_coast_hosts + dir.dc( :newyork ).ou( :hosts )
28
28
  # all_ns_hosts = all_hosts.filter( :cn => 'ns*' )
29
- #
29
+ #
30
30
  # Note that you could accomplish most of what BranchCollection does
31
31
  # using filters, but some people might find this a bit more readable.
32
32
  class Treequel::BranchCollection
33
33
  include Enumerable,
34
- Treequel::Loggable,
35
34
  Treequel::Constants
36
35
 
37
- extend Treequel::Delegation
36
+ extend Loggability,
37
+ Treequel::Delegation
38
+
39
+
40
+ # Loggability API -- Log to the Treequel module's logger
41
+ log_to :treequel
38
42
 
39
43
 
40
44
  #################################################################
@@ -43,11 +43,14 @@ require 'treequel/control'
43
43
  # Branchsets are Enumerable objects, so they can be manipulated using any of the
44
44
  # Enumerable methods, such as map, inject, etc.
45
45
  class Treequel::Branchset
46
+ extend Loggability
46
47
  include Enumerable,
47
- Treequel::Loggable,
48
48
  Treequel::Constants,
49
49
  Treequel::Control
50
50
 
51
+ # Loggability API -- Log to the Treequel module's logger
52
+ log_to :treequel
53
+
51
54
  # The default scope to use when searching if none is specified
52
55
  DEFAULT_SCOPE = :subtree
53
56
  DEFAULT_SCOPE.freeze
@@ -15,11 +15,15 @@ require 'treequel/branch'
15
15
  # The object in Treequel that represents a connection to a directory, the
16
16
  # binding to that directory, and the base from which all DNs start.
17
17
  class Treequel::Directory
18
- include Treequel::Loggable,
19
- Treequel::Constants,
18
+ include Treequel::Constants,
20
19
  Treequel::HashUtilities
21
20
 
22
- extend Treequel::Delegation
21
+ extend Loggability,
22
+ Treequel::Delegation
23
+
24
+ # Loggability API -- Log to the Treequel module's logger
25
+ log_to :treequel
26
+
23
27
 
24
28
  # The default directory options
25
29
  DEFAULT_OPTIONS = {
@@ -146,7 +150,7 @@ class Treequel::Directory
146
150
  end
147
151
 
148
152
 
149
- ### Copy constructor -- the duplicate should have a distinct connection, bound user,
153
+ ### Copy constructor -- the duplicate should have a distinct connection, bound user,
150
154
  ### and should have a distinct copy of the +original+'s registered controls.
151
155
  def initialize_copy( original )
152
156
  @conn = nil
@@ -37,12 +37,20 @@ require 'treequel/sequel_integration'
37
37
  # value = AttributeValue from Section 4.1.6 of [1]
38
38
  #
39
39
  class Treequel::Filter
40
- include Treequel::Loggable,
41
- Treequel::Constants::Patterns
40
+ extend Loggability
41
+ include Treequel::Constants::Patterns
42
+
43
+
44
+ # Loggability API -- Log to the Treequel module's logger
45
+ log_to :treequel
46
+
42
47
 
43
48
  ### Filter list component of a Treequel::Filter.
44
49
  class FilterList
45
- include Treequel::Loggable
50
+ extend Loggability
51
+
52
+ # Loggability API -- Log to the Treequel module's logger
53
+ log_to :treequel
46
54
 
47
55
  ### Create a new filter list with the given +filters+ in it.
48
56
  def initialize( *filters )
@@ -75,11 +83,15 @@ class Treequel::Filter
75
83
  ### An abstract class for filter components.
76
84
  ### Subclass and override #to_s to implement a custom Component class.
77
85
  class Component
78
- include Treequel::Loggable
86
+ extend Loggability
87
+
88
+ # Loggability API -- Log to the Treequel module's logger
89
+ log_to :treequel
79
90
 
80
91
  # Hide this class's new method
81
92
  private_class_method :new
82
93
 
94
+
83
95
  ### Inherited hook: re-expose inheriting class's .new method
84
96
  def self::inherited( klass )
85
97
  klass.module_eval( 'public_class_method :new' )
@@ -323,7 +335,7 @@ class Treequel::Filter
323
335
  raise Treequel::ExpressionError,
324
336
  "unable to parse %p as a substring literal" % [ literal ]
325
337
 
326
- Treequel.logger.debug " parsed substring literal as: %p" % [ match.captures ]
338
+ self.log.debug " parsed substring literal as: %p" % [ match.captures ]
327
339
  return self.new( *(match.captures.values_at(1,3,2)) )
328
340
  end
329
341
 
@@ -408,7 +420,7 @@ class Treequel::Filter
408
420
  ### Turn the specified filter +expression+ into a Treequel::Filter::Component
409
421
  ### object and return it.
410
422
  def self::parse_expression( expression )
411
- Treequel.logger.debug "Parsing expression %p" % [ expression ]
423
+ self.log.debug "Parsing expression %p" % [ expression ]
412
424
  expression = expression[0] if expression.is_a?( Array ) && expression.length == 1
413
425
 
414
426
  case expression
@@ -447,19 +459,19 @@ class Treequel::Filter
447
459
  ### Turn the specified expression Array into a Treequel::Filter::Component object
448
460
  ### and return it.
449
461
  def self::parse_array_expression( expression )
450
- Treequel.logger.debug "Parsing Array expression %p" % [ expression ]
462
+ self.log.debug "Parsing Array expression %p" % [ expression ]
451
463
 
452
464
  case
453
465
 
454
466
  # [ ] := '(objectClass=*)'
455
467
  when expression.empty?
456
- Treequel.logger.debug " empty expression -> objectClass presence item component"
468
+ self.log.debug " empty expression -> objectClass presence item component"
457
469
  return Treequel::Filter::PresentItemComponent.new
458
470
 
459
471
  # Collection of subfilters
460
472
  # [ [:uid, 'mahlon'], [:employeeNumber, 20202] ]
461
473
  when expression.all? {|elem| elem.is_a?(Array) }
462
- Treequel.logger.debug " parsing array of subfilters"
474
+ self.log.debug " parsing array of subfilters"
463
475
  filters = expression.collect {|exp| Treequel::Filter.new(exp) }
464
476
  if filters.length > 1
465
477
  return Treequel::Filter::AndComponent.new( filters )
@@ -494,22 +506,22 @@ class Treequel::Filter
494
506
  ### Parse one or more tuples contained in a Hash into an ANDed set of
495
507
  ### Treequel::Filter::Components and return it.
496
508
  def self::parse_hash_expression( expression )
497
- Treequel.logger.debug "Parsing Hash expression %p" % [ expression ]
509
+ self.log.debug "Parsing Hash expression %p" % [ expression ]
498
510
 
499
511
  filterlist = expression.collect do |key, expr|
500
- Treequel.logger.debug " adding %p => %p to the filter list" % [ key, expr ]
512
+ self.log.debug " adding %p => %p to the filter list" % [ key, expr ]
501
513
  if expr.respond_to?( :fetch )
502
514
  if expr.respond_to?( :length ) && expr.length > 1
503
- Treequel.logger.debug " ORing together %d subfilters since %p has indices" %
515
+ self.log.debug " ORing together %d subfilters since %p has indices" %
504
516
  [ expr.length, expr ]
505
517
  subfilters = expr.collect {|val| Treequel::Filter.new(key, val) }
506
518
  Treequel::Filter.new( :or, subfilters )
507
519
  else
508
- Treequel.logger.debug " unwrapping singular subfilter"
520
+ self.log.debug " unwrapping singular subfilter"
509
521
  Treequel::Filter.new([ key.to_sym, expr.first ])
510
522
  end
511
523
  else
512
- Treequel.logger.debug " value is a scalar; creating a single filter"
524
+ self.log.debug " value is a scalar; creating a single filter"
513
525
  Treequel::Filter.new( key.to_sym, expr )
514
526
  end
515
527
  end
@@ -525,7 +537,7 @@ class Treequel::Filter
525
537
  ### Parse a tuple of the form: [ Symbol, Object ] into a Treequel::Filter::Component
526
538
  ### and return it.
527
539
  def self::parse_tuple_array_expression( expression )
528
- Treequel.logger.debug "Parsing tuple Array expression %p" % [ expression ]
540
+ self.log.debug "Parsing tuple Array expression %p" % [ expression ]
529
541
 
530
542
  case expression[1]
531
543
 
@@ -535,7 +547,7 @@ class Treequel::Filter
535
547
  return self.parse_logical_array_expression( *expression )
536
548
 
537
549
  when Range
538
- Treequel.logger.debug " two ANDed item expressions from a Range"
550
+ self.log.debug " two ANDed item expressions from a Range"
539
551
  attribute = expression[0]
540
552
  range = expression[1]
541
553
  left = "#{attribute}>=#{range.begin}"
@@ -545,7 +557,7 @@ class Treequel::Filter
545
557
  # [ :attribute, 'value' ] := '(attribute=value)'
546
558
  # when String, Symbol, Numeric, Time
547
559
  else
548
- Treequel.logger.debug " item expression from a %p" % [ expression[1].class ]
560
+ self.log.debug " item expression from a %p" % [ expression[1].class ]
549
561
  return self.parse_item_component( *expression )
550
562
  end
551
563
  end
@@ -554,7 +566,7 @@ class Treequel::Filter
554
566
  ### Break down the given +expression+ as a logical (AND, OR, or NOT)
555
567
  ### filter component and return it.
556
568
  def self::parse_logical_array_expression( op, *components )
557
- Treequel.logger.debug "Parsing logical %p expression with components: %p" %
569
+ self.log.debug "Parsing logical %p expression with components: %p" %
558
570
  [ op, components ]
559
571
 
560
572
  compclass = LOGICAL_COMPONENTS[ op ] or
@@ -562,7 +574,7 @@ class Treequel::Filter
562
574
  [ op, LOGICAL_COMPONENTS.keys ]
563
575
 
564
576
  filterlist = components.collect do |filterexp|
565
- Treequel.logger.debug " making %p into a component" % [ filterexp ]
577
+ self.log.debug " making %p into a component" % [ filterexp ]
566
578
  Treequel::Filter.new( filterexp )
567
579
  end.flatten
568
580
 
@@ -572,7 +584,7 @@ class Treequel::Filter
572
584
 
573
585
  ### Parse an item component from the specified +attribute+ and +value+
574
586
  def self::parse_item_component( attribute, value )
575
- Treequel.logger.debug " tuple expression (%p=%p)-> item component" %
587
+ self.log.debug " tuple expression (%p=%p)-> item component" %
576
588
  [ attribute, value ]
577
589
 
578
590
  case
@@ -590,7 +602,7 @@ class Treequel::Filter
590
602
 
591
603
  ### Parse a Sequel::SQL::Expression as a Treequel::Filter::Component and return it.
592
604
  def self::parse_sequel_expression( expression )
593
- Treequel.logger.debug " parsing Sequel expression: %p" % [ expression ]
605
+ self.log.debug " parsing Sequel expression: %p" % [ expression ]
594
606
 
595
607
  if expression.respond_to?( :op )
596
608
  op = expression.op.to_s.downcase.to_sym
@@ -601,11 +613,11 @@ class Treequel::Filter
601
613
  # Turn :sn.like( 'bob' ) into (cn~=bob) 'cause it has no asterisks
602
614
  if op == :like
603
615
  if value.index( '*' )
604
- Treequel.logger.debug \
616
+ self.log.debug \
605
617
  " turning a LIKE expression with an asterisk into a substring filter"
606
618
  return Treequel::Filter::SubstringItemComponent.new( attribute, value )
607
619
  else
608
- Treequel.logger.debug \
620
+ self.log.debug \
609
621
  " turning a LIKE expression with no wildcards into an 'approx' filter"
610
622
  equivalent = :approx
611
623
  end
@@ -618,7 +630,7 @@ class Treequel::Filter
618
630
  return Treequel::Filter::NotComponent.new( contents )
619
631
 
620
632
  elsif op == :'not like'
621
- Treequel.logger.debug " making a NOT LIKE expression out of: %p" % [ expression ]
633
+ self.log.debug " making a NOT LIKE expression out of: %p" % [ expression ]
622
634
  attribute, value = *expression.args
623
635
  component = nil
624
636