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

Methods included from GetTextSupport

included

Constructor Details

#initialize(*rdns) ⇒ DistinguishedName

Returns a new instance of DistinguishedName.



158
159
160
161
162
163
# File 'lib/active_ldap/distinguished_name.rb', line 158

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

Instance Attribute Details

#rdnsObject (readonly)

Returns the value of attribute rdns.



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

def rdns
  @rdns
end

Class Method Details

.parse(source) ⇒ Object



152
153
154
# File 'lib/active_ldap/distinguished_name.rb', line 152

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

Instance Method Details

#-(other) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/active_ldap/distinguished_name.rb', line 165

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

#<<(rdn) ⇒ Object



178
179
180
# File 'lib/active_ldap/distinguished_name.rb', line 178

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

#<=>(other) ⇒ Object



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

def <=>(other)
  normalize_for_comparing(@rdns) <=>
    normalize_for_comparing(other.rdns)
end

#==(other) ⇒ Object



191
192
193
194
# File 'lib/active_ldap/distinguished_name.rb', line 191

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
199
# File 'lib/active_ldap/distinguished_name.rb', line 196

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

#hashObject



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

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

#inspectObject



205
206
207
# File 'lib/active_ldap/distinguished_name.rb', line 205

def inspect
  super
end

#to_sObject



209
210
211
212
213
214
215
216
217
# File 'lib/active_ldap/distinguished_name.rb', line 209

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

#unshift(rdn) ⇒ Object



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

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