Project

General

Profile

Download (2.75 KB) Statistics
| Branch: | Tag: | Revision:
#--
# LdapShadows, a Medium-level LDAP Access Library and Tool.
# Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++


module LdapShadows
module Elements
module LdapElement
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
# initializers
def cast
if @cast_done
raise_error _("element '%s' already initialized") % self.handle
end
@cast_done = true
end
def cast_relations
if @cast_rel_done
raise_error _("element '%s' already post-initialized") % self.handle
end
@cast_rel_done = true
end

def virtual_attributes
(@virtual_attributes || {}).keys
end

def ldap_virtual_attr(attr, syntax, single_value = false, binary = false)
@virtual_attributes ||= {}
@virtual_attributes[attr.to_s] = {
:syntax => syntax,
:single_value => single_value,
:binary => binary
}
end

def real_attribute_info(attr)
attr_info = ActiveLdap::Base.schema.attribute(attr)
return if attr_info.nil?

{
:syntax => attr_info.syntax.to_param,
:single_value => attr_info.single_value?,
:read_only => attr_info.read_only?,
:binary => attr_info.binary?
}
end

def virtual_attribute_info(attr)
info = (@virtual_attributes || {})[attr.to_s]
return if info.nil?

info.dup.merge({
:read_only => (not self.instance_methods.include?("#{attr}="))
})
end

# default empty hooks
def hook_before_create(item); end
def hook_before_modify(item); end
def hook_before_delete(item); end
def hook_after_create(item); end
def hook_after_modify(item); end
def hook_after_delete(item); end

protected

def raise_error(msg)
raise ProcessingError, msg
end
end
end
end
end

require 'ldap_shadows/elements/object'
require 'ldap_shadows/elements/aspect'
(4-4/9)