def Base.create_object(config={})
str = config[:class]
class_name = str[0].chr.upcase + str[1..-1]
attr = config[:dnattr]
prefix = config[:base]
classes_array = config[:classes] || []
belongs_to_array = config[:belongs_to] || []
has_many_array = config[:has_many] || []
raise TypeError, ":objectclasses must be an array" unless classes_array.respond_to? :size
raise TypeError, ":belongs_to must be an array" unless belongs_to_array.respond_to? :size
raise TypeError, ":has_many must be an array" unless has_many_array.respond_to? :size
classes = '['
classes_array.map! {|x| x = "'#{x}'"}
classes << classes_array.join(', ')
classes << ']'
belongs_to = []
if belongs_to_array.size > 0
belongs_to_array.each do |bt|
line = [ "belongs_to :#{bt[0]}" ]
bt[1].keys.each do |key|
line << ":#{key} => '#{bt[1][key]}'"
end
belongs_to << line.join(', ')
end
end
has_many = []
if has_many_array.size > 0
has_many_array.each do |hm|
line = [ "has_many :#{hm[0]}" ]
hm[1].keys.each do |key|
line << ":#{key} => '#{hm[1][key]}'"
end
has_many << line.join(', ')
end
end
self.class.module_eval "class ::\#{class_name} < ActiveLDAP::Base\nldap_mapping :dnattr => \"\#{attr}\", :prefix => \"\#{prefix}\", :classes => \#{classes}\n\#{belongs_to.join(\"\\n\")}\n\#{has_many.join(\"\\n\")}\nend\n"
end