Class: ActiveLdap::DistinguishedName

Inherits:
Object
  • Object
show all
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

#initialize(*rdns) ⇒ DistinguishedName

Returns a new instance of DistinguishedName.



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

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.



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

def rdns
  @rdns
end

Class Method Details

.parse(source) ⇒ Object



148
149
150
# File 'lib/active_ldap/distinguished_name.rb', line 148

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

Instance Method Details

#-(other) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/active_ldap/distinguished_name.rb', line 161

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, "#{other} isn't sub DN of #{self}"
    end
  end
  self.class.new(*rdns)
end

#<<(rdn) ⇒ Object



174
175
176
# File 'lib/active_ldap/distinguished_name.rb', line 174

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

#<=>(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

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

#inspectObject



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

def inspect
  super
end

#to_sObject



205
206
207
208
209
210
211
212
213
# File 'lib/active_ldap/distinguished_name.rb', line 205

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



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

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