Sha256: 8db0719db01df1a3d8feeebb97723c4ee52c15bcd58fdc5bf3844e0fc3667d2b

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

class Acs::Ldap::Model

  def initialize(connector, options = {})
    @connector = connector
    @id = options[:id] || :id
  end

  def ou
    @ou
  end

  def base
    "ou=#{ou},#{@connector.base}"
  end

  def dn(model)
    "uid=#{model.send @id},#{base}"
  end

  def find_by(key, value)
    @connector.search_by(
      base,
      key,
      value
    )
  end

  def create(model)
    attributes = attributes(model).except!(:uid)
    attributes.merge!(objectClass: object_class)

    @connector.add(
      dn(model),
      #base,
      attributes
    )
  end

  def update(model, attributes = nil)
    operations = []
    update_attributes = []
    update_attributes << attributes
    update_attributes.flatten
    attributes(model).each do |sym, value|
      if attributes == nil || update_attributes.include?(sym)
        operations << [:replace, sym.to_s, value] unless sym.to_s == "uid"
      end
    end
    @connector.update(
      dn(model),
      operations
    )
  end

  def destroy(model)
    @connector.delete(dn(model))
  end

  def flush
    @connector.delete_all(ou)
  end

  def count
    count = 0
    @connector.search({base: base}).data.each do |entry|
      count += 1 if entry[:uid].present?
    end
    count
  end

  def exist?(model)
    @connector.search({base: dn(model)}).data.length > 0
  end

protected

  def logger
    Acs::Ldap.logger
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acs-ldap-0.1.4 lib/acs/ldap/model.rb
acs-ldap-0.1.3 lib/acs/ldap/model.rb
acs-ldap-0.1.2 lib/acs/ldap/model.rb