Module ActiveLdap::Associations::ClassMethods
In: lib/active_ldap/associations.rb
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired AdapterNotFound ConnectionNotEstablished TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError DistinguishedNameInvalid DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_44_0.png

Methods

Constants

VALID_BELONGS_TO_OPTIONS = [:class, :foreign_key, :primary_key, :many, :extend]
VALID_HAS_MANY_OPTIONS = [:class, :foreign_key, :primary_key, :wrap, :extend]

Public Instance methods

[Source]

    # File lib/active_ldap/associations.rb, line 26
26:       def associated_class(name)
27:         @associated_classes[name.to_s]
28:       end

belongs_to

This defines a method for an extension class map its DN key attribute value on to multiple items which reference it by |:foreign_key| in the other LDAP entry covered by class |:class_name|.

Example:

 belongs_to :groups, :class_name => "Group",
            :many => "memberUid" # Group#memberUid
            # :foreign_key => "uid" # User#uid
            # dn attribute value is used by default
 belongs_to :primary_group, :class_name => "Group",
            :foreign_key => "gidNumber", # User#gidNumber
            :primary_key => "gidNumber"  # Group#gidNumber

[Source]

    # File lib/active_ldap/associations.rb, line 45
45:       def belongs_to(association_id, options={})
46:         validate_belongs_to_options(options)
47:         klass = options[:class] || association_id.to_s.classify
48:         foreign_key = options[:foreign_key]
49:         primary_key = options[:primary_key]
50:         many = options[:many]
51:         set_associated_class(association_id, klass)
52: 
53:         opts = {
54:           :association_id => association_id,
55:           :foreign_key_name => foreign_key,
56:           :primary_key_name => primary_key,
57:           :many => many,
58:           :extend => options[:extend],
59:         }
60:         if opts[:many]
61:           association_class = Association::BelongsToMany
62:           opts[:foreign_key_name] ||= dn_attribute
63:         else
64:           association_class = Association::BelongsTo
65:           opts[:foreign_key_name] ||= "#{association_id}_id"
66: 
67:           before_save("if defined?(@\#{association_id})\nassociation = @\#{association_id}\nif association and association.updated?\nself[association.__send__(:primary_key)] =\nassociation[\#{opts[:foreign_key_name].dump}]\nend\nend\n")
68:         end
69: 
70:         association_accessor(association_id) do |target|
71:           association_class.new(target, opts)
72:         end
73:       end

has_many

This defines a method for an extension class expand an existing multi-element attribute into ActiveLdap objects. This discards any calls which result in entries that don‘t exist in LDAP!

Example:

  has_many :primary_members, :class_name => "User",
           :primary_key => "gidNumber", # User#gidNumber
           :foreign_key => "gidNumber"  # Group#gidNumber
  has_many :members, :class_name => "User",
           :wrap => "memberUid" # Group#memberUid

[Source]

     # File lib/active_ldap/associations.rb, line 98
 98:       def has_many(association_id, options = {})
 99:         validate_has_many_options(options)
100:         klass = options[:class] || association_id.to_s.classify
101:         foreign_key = options[:foreign_key] || "#{association_id}_id"
102:         primary_key = options[:primary_key]
103:         set_associated_class(association_id, klass)
104: 
105:         opts = {
106:           :association_id => association_id,
107:           :foreign_key_name => foreign_key,
108:           :primary_key_name => primary_key,
109:           :wrap => options[:wrap],
110:           :extend => options[:extend],
111:         }
112:         if opts[:wrap]
113:           association_class = Association::HasManyWrap
114:         else
115:           association_class = Association::HasMany
116:         end
117: 
118:         association_accessor(association_id) do |target|
119:           association_class.new(target, opts)
120:         end
121:       end

[Source]

    # File lib/active_ldap/associations.rb, line 21
21:       def set_associated_class(name, klass)
22:         @associated_classes ||= {}
23:         @associated_classes[name.to_s] = klass
24:       end

Private Instance methods

[Source]

     # File lib/active_ldap/associations.rb, line 124
124:       def association_accessor(name, &make_association)
125:         define_method("__make_#{name}") do
126:           make_association.call(self)
127:         end
128:         associations << name
129:         association_reader(name, &make_association)
130:         association_writer(name, &make_association)
131:       end

[Source]

     # File lib/active_ldap/associations.rb, line 133
133:       def association_reader(name, &make_association)
134:         class_eval("def \#{name}\n@\#{name} ||= __make_\#{name}\nend\n", __FILE__, __LINE__ + 1)
135:       end

[Source]

     # File lib/active_ldap/associations.rb, line 142
142:       def association_writer(name, &make_association)
143:         class_eval("def \#{name}=(new_value)\nassociation = defined?(@\#{name}) ? @\#{name} : nil\nassociation ||= __make_\#{name}\nassociation.replace(new_value)\n@\#{name} = new_value.nil? ? nil : association\n@\#{name}\nend\n", __FILE__, __LINE__ + 1)
144:       end

[Source]

     # File lib/active_ldap/associations.rb, line 157
157:       def validate_belongs_to_options(options)
158:         options.assert_valid_keys(VALID_BELONGS_TO_OPTIONS)
159:       end

[Source]

     # File lib/active_ldap/associations.rb, line 163
163:       def validate_has_many_options(options)
164:         options.assert_valid_keys(VALID_HAS_MANY_OPTIONS)
165:       end

[Validate]