Class: ActiveLdap::DistinguishedName — activeldap - ActiveLdap

Class: ActiveLdap::DistinguishedName

Inherits:
Object
  • Object
show all
Includes:
GetTextSupport
Defined in:
lib/active_ldap/distinguished_name.rb

Defined Under Namespace

Classes: Parser

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DistinguishedName) initialize(*rdns)

Returns a new instance of DistinguishedName



171
172
173
174
175
176
177
178
179
# File 'lib/active_ldap/distinguished_name.rb', line 171

def initialize(*rdns)
  @rdns = rdns.collect do |rdn|
    if rdn.is_a?(Array) and rdn.size == 2
      {rdn[0] => rdn[1]}
    else
      rdn
    end
  end
end

Instance Attribute Details

- (Object) rdns (readonly)

Returns the value of attribute rdns



170
171
172
# File 'lib/active_ldap/distinguished_name.rb', line 170

def rdns
  @rdns
end

Class Method Details

+ (Object) escape_value(value)



161
162
163
164
165
166
167
# File 'lib/active_ldap/distinguished_name.rb', line 161

def escape_value(value)
  if /(\A | \z)/.match(value)
    '"' + value.gsub(/([\\\"])/, '\\\\\1') + '"'
  else
    value.gsub(/([,=\+<>#;\\\"])/, '\\\\\1')
  end
end

+ (Object) parse(source)



157
158
159
# File 'lib/active_ldap/distinguished_name.rb', line 157

def parse(source)
  Parser.new(source).parse
end

Instance Method Details

- (Object) +(other)



185
186
187
# File 'lib/active_ldap/distinguished_name.rb', line 185

def +(other)
  self.class.new(*(@rdns + other.rdns))
end

- (Object) -(other)



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/active_ldap/distinguished_name.rb', line 189

def -(other)
  rdns = @rdns.dup
  normalized_rdns = normalize(@rdns)
  normalize(other.rdns).reverse_each do |rdn|
    if rdn == normalized_rdns.pop
      rdns.pop
    else
      raise ArgumentError, _("%s isn't sub DN of %s") % [other, self]
    end
  end
  self.class.new(*rdns)
end

- (Object) <<(rdn)



202
203
204
205
# File 'lib/active_ldap/distinguished_name.rb', line 202

def <<(rdn)
  @rdns << rdn
  self
end

- (Object) <=>(other)



216
217
218
219
220
221
# File 'lib/active_ldap/distinguished_name.rb', line 216

def <=>(other)
  other = DN.parse(other) if other.is_a?(String)
  return nil unless other.is_a?(self.class)
  normalize_for_comparing(@rdns) <=>
    normalize_for_comparing(other.rdns)
end

- (Object) ==(other)



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/active_ldap/distinguished_name.rb', line 223

def ==(other)
  case other
  when self.class
    normalize(@rdns) == normalize(other.rdns)
  when String
    parsed_other = nil
    begin
      parsed_other = self.class.parse(other)
    rescue DistinguishedNameInvalid
      return false
    end
    self == parsed_other
  else
    false
  end
end

- (Boolean) blank?

Returns:

  • (Boolean)


181
182
183
# File 'lib/active_ldap/distinguished_name.rb', line 181

def blank?
  @rdns.blank?
end

- (Boolean) eql?(other)

Returns:

  • (Boolean)


240
241
242
243
# File 'lib/active_ldap/distinguished_name.rb', line 240

def eql?(other)
  other.is_a?(self.class) and
    normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s)
end

- (Object) hash



245
246
247
# File 'lib/active_ldap/distinguished_name.rb', line 245

def hash
  normalize(@rdns).to_s.hash
end

- (Object) parent



211
212
213
214
# File 'lib/active_ldap/distinguished_name.rb', line 211

def parent
  return nil if @rdns.size <= 1
  self.class.new(*@rdns[1..-1])
end

- (Object) to_human_readable_format



264
265
266
# File 'lib/active_ldap/distinguished_name.rb', line 264

def to_human_readable_format
  to_s.inspect
end

- (Object) to_s



249
250
251
252
253
254
255
256
257
258
# File 'lib/active_ldap/distinguished_name.rb', line 249

def to_s
  klass = self.class
  @rdns.collect do |rdn|
    rdn.sort_by do |type, value|
      type.upcase
    end.collect do |type, value|
      "#{type}=#{klass.escape_value(value)}"
    end.join("+")
  end.join(",")
end

- (Object) to_str

for backward compatibility



260
261
262
# File 'lib/active_ldap/distinguished_name.rb', line 260

def to_str # for backward compatibility
  to_s
end

- (Object) unshift(rdn)



207
208
209
# File 'lib/active_ldap/distinguished_name.rb', line 207

def unshift(rdn)
  @rdns.unshift(rdn)
end