Revision c2c26953
Added by Marc Dequènes about 14 years ago
- ID c2c269539e77e757f52a43ef19de5c5c6f85ae1e
conf/ldap_shadows/worlds/OpenLDAP_config/shadows/Administration/plugins/aspects/database_hdb.rb | ||
---|---|---|
|
||
# should methods be generated by metaprogramming ?
|
||
# (to ensure type_cast/normalize_value and not to repeat attr parameters)
|
||
|
||
ldap_virtual_attr :plopToto2, '1.3.6.1.4.1.1466.115.121.1.15'
|
||
|
||
def plopToto2(always_array = true)
|
||
val = "#{self.olcMaxDerefDepth} #{self.olcDbMode}"
|
||
(always_array) ? [val] : val
|
||
end
|
||
|
||
def plopToto2=(val)
|
||
pp self.schema.ldap_syntax('1.3.6.1.4.1.1466.115.121.1.15').normalize_value(367)
|
||
end
|
||
|
lib/ldap_shadows/elements.rb | ||
---|---|---|
@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
|
lib/ldap_shadows/elements/aspect.rb | ||
---|---|---|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
#++
|
||
|
||
require 'delegate'
|
||
|
||
module LdapShadows
|
||
module Elements
|
||
class LdapAspect
|
||
class LdapAspect < Delegator
|
||
include LdapElement
|
||
|
||
def initialize(obj)
|
||
super
|
||
@_sd_obj = obj
|
||
end
|
||
|
||
def __getobj__
|
||
@_sd_obj
|
||
end
|
||
|
||
def self.cast_relations
|
||
super
|
||
|
lib/ldap_shadows/elements/object.rb | ||
---|---|---|
|
||
class << self
|
||
attr_reader :relations_info
|
||
|
||
def virtual_attributes
|
||
(@virtual_attributes || {}).keys
|
||
end
|
||
end
|
||
|
||
def virtual_attributes
|
||
# TODO: add aspects attributes
|
||
self.class.virtual_attributes
|
||
end
|
||
|
||
# default
|
||
... | ... | |
|
||
@parent_changed = false
|
||
@latest_parent_full_handle = nil
|
||
@aspects_inst_cache = {}
|
||
end
|
||
|
||
def self.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 self.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 self.virtual_attribute_info(attr)
|
||
info = @virtual_attributes[attr.to_s].dup
|
||
info.merge({
|
||
:read_only => (not self.instance_methods.include?("#{attr}="))
|
||
})
|
||
def virtual_attributes
|
||
list = self.class.virtual_attributes
|
||
aspects.values.each do |aspect|
|
||
list += aspect.virtual_attributes
|
||
end
|
||
end
|
||
|
||
# return nil if not found
|
||
def attribute_info(attr)
|
||
if self.has_attribute? attr
|
||
self.class.real_attribute_info(attr)
|
||
else
|
||
self.class.virtual_attribute_info(attr)
|
||
return self.class.real_attribute_info(attr) if self.has_attribute? attr
|
||
|
||
info = self.class.virtual_attribute_info(attr)
|
||
return info unless info.nil?
|
||
|
||
aspects.values.each do |aspect|
|
||
info = aspect.virtual_attribute_info(attr)
|
||
return info unless info.nil?
|
||
end
|
||
end
|
||
|
||
... | ... | |
|
||
def has_field?(field)
|
||
return false if field.downcase == "objectclass"
|
||
has_attribute?(field) || virtual_attributes.include?(field)
|
||
return true if has_attribute?(field)
|
||
return true if virtual_attributes.include?(field)
|
||
aspects.values.each do |aspect|
|
||
return true if aspect.virtual_attributes.include?(field)
|
||
end
|
||
return false
|
||
end
|
||
|
||
def human_name
|
||
... | ... | |
unless attr_list.empty?
|
||
self.aspects.values.each do |aspect|
|
||
taken_attr_list = (aspect.possible_attributes & attr_list)
|
||
taken_attr_list += aspect.virtual_attributes
|
||
obj_aspects[aspect.handle] ||= {}
|
||
obj_aspects[aspect.handle].merge!(fetch_attributes_data(taken_attr_list, expert_attributes, admin_attributes))
|
||
attr_list -= taken_attr_list
|
||
... | ... | |
r
|
||
end
|
||
|
||
def method_missing(method, *args)
|
||
aspects.each_pair do |aspect_name, aspect|
|
||
if aspect.instance_methods.include? method.to_s
|
||
aspect_inst = @aspects_inst_cache[aspect_name]
|
||
if aspect_inst.nil?
|
||
aspect_inst = aspect.new(self)
|
||
@aspects_inst_cache[aspect_name] = aspect_inst
|
||
end
|
||
return aspect_inst.send(method, *args)
|
||
end
|
||
end
|
||
|
||
super
|
||
end
|
||
|
||
protected
|
||
|
||
def before_save_jobs
|
Also available in: Unified diff
[evol] virtual attributes support §2 (aspect vattrs with example) (refs #141)