root/lib/ldap_shadows/elements.rb @ 4b490148
88b0bbce | Marc Dequènes (Duck) | #--
|
|
# LdapShadows, a Medium-level LDAP Access Library and Tool.
|
|||
bc2c2691 | Marc Dequènes (Duck) | # Copyright (c) 2009-2010 Marc Dequènes (Duck) <Duck@DuckCorp.org>
|
|
88b0bbce | Marc Dequènes (Duck) | #
|
|
# 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
|
|||
90809ae4 | Marc Dequènes (Duck) | module Elements
|
|
module LdapElement
|
|||
def self.included(base)
|
|||
base.extend(ClassMethods)
|
|||
end
|
|||
88b0bbce | Marc Dequènes (Duck) | ||
90809ae4 | Marc Dequènes (Duck) | module ClassMethods
|
|
# initializers
|
|||
f25d0aed | Marc Dequènes (Duck) | 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
|
|||
88b0bbce | Marc Dequènes (Duck) | ||
c2c26953 | Marc Dequènes (Duck) | 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] = {
|
|||
66e78c7a | Marc Dequènes (Duck) | :syntax => syntax,
|
|
:single_value => single_value,
|
|||
:binary => binary,
|
|||
:operational => false
|
|||
c2c26953 | Marc Dequènes (Duck) | }
|
|
end
|
|||
def real_attribute_info(attr)
|
|||
attr_info = ActiveLdap::Base.schema.attribute(attr)
|
|||
return if attr_info.nil?
|
|||
{
|
|||
66e78c7a | Marc Dequènes (Duck) | :syntax => attr_info.syntax.to_param,
|
|
:single_value => attr_info.single_value?,
|
|||
:read_only => attr_info.read_only?,
|
|||
:binary => attr_info.binary?,
|
|||
:operational => attr_info.directory_operation?
|
|||
c2c26953 | Marc Dequènes (Duck) | }
|
|
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
|
|||
90809ae4 | Marc Dequènes (Duck) | # default empty hooks
|
|
953a2b4d | Marc Dequènes (Duck) | 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
|
|||
88b0bbce | Marc Dequènes (Duck) | ||
90809ae4 | Marc Dequènes (Duck) | protected
|
|
f25d0aed | Marc Dequènes (Duck) | def raise_error(msg)
|
|
90809ae4 | Marc Dequènes (Duck) | raise ProcessingError, msg
|
|
end
|
|||
88b0bbce | Marc Dequènes (Duck) | end
|
|
end
|
|||
end
|
|||
end
|
|||
90809ae4 | Marc Dequènes (Duck) | ||
require 'ldap_shadows/elements/object'
|
|||
require 'ldap_shadows/elements/aspect'
|