@@ -75,17 +75,27 @@ class Entry
75
75
76
76
# This constructor is not generally called by user code.
77
77
#--
78
- # Originally, myhash took a block so we wouldn't have to
78
+ # Originally, attributes took a block so we wouldn't have to
79
79
# make sure its elements returned empty arrays when necessary.
80
80
# Got rid of that to enable marshalling of Entry objects,
81
81
# but that doesn't work anyway, because Entry objects have
82
82
# singleton methods. So we define a custom dump and load.
83
- def initialize dn = nil # :nodoc:
84
- @myhash = { } # originally: Hash.new {|k,v| k[v] = [] }
85
- @myhash [ :dn ] = [ dn ]
83
+ def initialize ( dn = nil ) # :nodoc:
84
+ @attributes = { } # originally: Hash.new {|k,v| k[v] = [] }
85
+ @attributes [ :dn ] = [ dn ]
86
86
end
87
87
88
- def _dump depth
88
+ def attributes
89
+ @attributes
90
+ end
91
+
92
+ protected :attributes
93
+
94
+ def ==( other )
95
+ self . attributes == other . attributes
96
+ end
97
+
98
+ def _dump ( depth )
89
99
to_ldif
90
100
end
91
101
@@ -98,21 +108,20 @@ def _load entry
98
108
#--
99
109
# Discovered bug, 26Aug06: I noticed that we're not converting the
100
110
# incoming value to an array if it isn't already one.
101
- def []= name , value # :nodoc:
111
+ def []=( name , value ) # :nodoc:
102
112
sym = name . to_s . downcase . intern
103
113
value = [ value ] unless value . is_a? ( Array )
104
- @myhash [ sym ] = value
114
+ @attributes [ sym ] = value
105
115
end
106
116
107
-
108
117
#--
109
118
# We have to deal with this one as we do with []=
110
119
# because this one and not the other one gets called
111
120
# in formulations like entry["CN"] << cn.
112
121
#
113
- def [] name # :nodoc:
122
+ def []( name ) # :nodoc:
114
123
name = name . to_s . downcase . intern unless name . is_a? ( Symbol )
115
- @myhash [ name ] || [ ]
124
+ @attributes [ name ] || @attributes [ name ] = [ ]
116
125
end
117
126
118
127
# Returns the dn of the Entry as a String.
@@ -122,7 +131,7 @@ def dn
122
131
123
132
# Returns an array of the attribute names present in the Entry.
124
133
def attribute_names
125
- @myhash . keys
134
+ @attributes . keys
126
135
end
127
136
128
137
# Accesses each of the attributes present in the Entry.
@@ -133,17 +142,15 @@ def attribute_names
133
142
#
134
143
def each
135
144
if block_given?
136
- attribute_names . each { |a |
145
+ attribute_names . each do |a |
137
146
attr_name , values = a , self [ a ]
138
147
yield attr_name , values
139
- }
148
+ end
140
149
end
141
150
end
142
151
143
152
alias_method :each_attribute , :each
144
153
145
-
146
-
147
154
# Converts the Entry to a String, representing the
148
155
# Entry's attributes in LDIF format.
149
156
#--
@@ -232,15 +239,15 @@ def method_missing *args, &block # :nodoc:
232
239
def write
233
240
end
234
241
235
-
236
242
#--
237
243
# Internal convenience method. It seems like the standard
238
244
# approach in most LDAP tools to base64 encode an attribute
239
245
# value if its first or last byte is nonprintable, or if
240
246
# it's a password. But that turns out to be not nearly good
241
247
# enough. There are plenty of A/D attributes that are binary
242
248
# in the middle. This is probably a nasty performance killer.
243
- def is_attribute_value_binary? value
249
+ #
250
+ def is_attribute_value_binary? ( value )
244
251
v = value . to_s
245
252
v . each_byte { |byt |
246
253
return true if ( byt < 32 ) || ( byt > 126 )
@@ -250,11 +257,9 @@ def is_attribute_value_binary? value
250
257
end
251
258
false
252
259
end
260
+
253
261
private :is_attribute_value_binary?
254
262
255
263
end # class Entry
256
264
257
- end # class LDAP
258
- end # module Net
259
-
260
-
265
+ end ; end # class Net::LDAP
0 commit comments