Class: LDAP::Mod

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap/mod.rb

Constant Summary collapse

BasicAttributes =
javax.naming.directory.BasicAttributes
BasicAttribute =
javax.naming.directory.BasicAttribute
ModificationItem =
javax.naming.directory.ModificationItem
DirContext =
javax.naming.directory.DirContext

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod_type, attr, vals) ⇒ Mod

Returns a new instance of Mod.



43
44
45
# File 'lib/ldap/mod.rb', line 43

def initialize(mod_type, attr, vals)
  @type, @attr, @vals = mod_type, attr, vals
end

Class Method Details

.ruby_mod_to_java(mod_op) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/ldap/mod.rb', line 27

def ruby_mod_to_java(mod_op)
  case (mod_op&~LDAP::LDAP_MOD_BVALUES)
    when LDAP::LDAP_MOD_ADD then DirContext::ADD_ATTRIBUTE
    when LDAP::LDAP_MOD_REPLACE then DirContext::REPLACE_ATTRIBUTE
    when LDAP::LDAP_MOD_DELETE then DirContext::REMOVE_ATTRIBUTE
    else raise LDAP::Error, "can't handle operation #{mod_op}"
  end
end

.to_java_attributes(*attrs) ⇒ Object



20
21
22
23
24
25
# File 'lib/ldap/mod.rb', line 20

def to_java_attributes(*attrs)
  attrs.inject(BasicAttributes.new) do |res, attr|
    res.put(attr.to_java_attribute)
    res
  end
end

.to_java_modification_items(*attrs) ⇒ Object



36
37
38
39
40
# File 'lib/ldap/mod.rb', line 36

def to_java_modification_items(*attrs)
  attrs.map do |val|
    ModificationItem.new(ruby_mod_to_java(val.mod_op), val.to_java_attribute)
  end.to_java ModificationItem
end

Instance Method Details

#mod_opObject

should be mod_type



47
48
49
# File 'lib/ldap/mod.rb', line 47

def mod_op #should be mod_type
  @type
end

#mod_typeObject

should be attr



51
52
53
# File 'lib/ldap/mod.rb', line 51

def mod_type #should be attr
  @attr
end

#mod_valsObject



55
56
57
# File 'lib/ldap/mod.rb', line 55

def mod_vals
  @vals
end

#to_java_attributeObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ldap/mod.rb', line 59

def to_java_attribute
  v = BasicAttribute.new(self.mod_type)
  binary = mod_op & LDAP::LDAP_MOD_BVALUES
  if binary != 0
    self.mod_vals.each do |val|
      v.add(val.to_java_bytes)
    end
  else
    self.mod_vals.each do |val|
      v.add(val)
    end
  end
  v
end