Class Index [+]

Quicksearch

ActiveLdap::Associations::ClassMethods

Constants

VALID_BELONGS_TO_OPTIONS
VALID_HAS_MANY_OPTIONS

Public Instance Methods

associated_class(name) click to toggle source
    # File lib/active_ldap/associations.rb, line 26
26:       def associated_class(name)
27:         @associated_classes[name.to_s]
28:       end
belongs_to(association_id, options={}) click to toggle source

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
            # :primary_key => "uid" # User#uid
            ## deprecated since 1.1.0. Use :primary_key instead.
            ## :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
    # File lib/active_ldap/associations.rb, line 48
48:       def belongs_to(association_id, options={})
49:         validate_belongs_to_options(options)
50:         klass = options[:class]
51:         klass ||= (options[:class_name] || association_id.to_s).classify
52:         foreign_key = options[:foreign_key]
53:         primary_key = options[:primary_key]
54:         many = options[:many]
55:         set_associated_class(association_id, klass)
56: 
57:         opts = {
58:           :association_id => association_id,
59:           :foreign_key_name => foreign_key,
60:           :primary_key_name => primary_key,
61:           :many => many,
62:           :extend => options[:extend],
63:         }
64:         if opts[:many]
65:           association_class = Association::BelongsToMany
66:           foreign_key_name = opts[:foreign_key_name]
67:           if foreign_key_name
68:             message = _(":foreign_key belongs_to(:many) option is "                          "deprecated since 1.1.0. Use :primary_key instead.")
69:             ActiveSupport::Deprecation.warn(message)
70:             opts[:primary_key_name] ||= foreign_key_name
71:           end
72:           opts[:primary_key_name] ||= dn_attribute
73:         else
74:           association_class = Association::BelongsTo
75:           opts[:foreign_key_name] ||= "#{association_id}_id"
76: 
77:           before_save(            if defined?(@#{association_id})              association = @#{association_id}              if association and association.updated?                self[association.__send__(:primary_key)] =                  association[#{opts[:foreign_key_name].dump}]              end            end)
78:         end
79: 
80:         association_accessor(association_id) do |target|
81:           association_class.new(target, opts)
82:         end
83:       end
has_many(association_id, options = {}) click to toggle source

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", # Group#gidNumber
           :foreign_key => "gidNumber"  # User#gidNumber
           ## deprecated since 1.1.0. Those options
           ## are inverted.
           # :primary_key => "gidNumber", # User#gidNumber
           # :foreign_key => "gidNumber"  # Group#gidNumber
  has_many :members, :class_name => "User",
           :wrap => "memberUid" # Group#memberUid
     # File lib/active_ldap/associations.rb, line 112
112:       def has_many(association_id, options = {})
113:         validate_has_many_options(options)
114:         klass = options[:class]
115:         klass ||= (options[:class_name] || association_id.to_s).classify
116:         foreign_key = options[:foreign_key]
117:         primary_key = options[:primary_key]
118:         set_associated_class(association_id, klass)
119: 
120:         opts = {
121:           :association_id => association_id,
122:           :foreign_key_name => foreign_key,
123:           :primary_key_name => primary_key,
124:           :wrap => options[:wrap],
125:           :extend => options[:extend],
126:         }
127:         if opts[:wrap]
128:           association_class = Association::HasManyWrap
129:         else
130:           association_class = Association::HasMany
131:           primary_key_name = opts[:primary_key_name]
132:           foreign_key_name = opts[:foreign_key_name]
133:           if primary_key_name != foreign_key_name and
134:               primary_key_name != "dn" and
135:               !new.have_attribute?(primary_key_name)
136:             message = _(":primary_key and :foreign_key has_many options are "                          "inverted their mean since 1.1.0. Please invert them.")
137:             ActiveSupport::Deprecation.warn(message)
138:             opts[:foreign_key_name] = primary_key_name
139:             opts[:primary_key_name] = foreign_key_name
140:           end
141:         end
142: 
143:         association_accessor(association_id) do |target|
144:           association_class.new(target, opts)
145:         end
146:       end
set_associated_class(name, klass) click to toggle 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

association_accessor(name, &make_association) click to toggle source
     # File lib/active_ldap/associations.rb, line 150
150:       def association_accessor(name, &make_association)
151:         define_method("__make_#{name}") do
152:           make_association.call(self)
153:         end
154:         associations << name
155:         association_reader(name, &make_association)
156:         association_writer(name, &make_association)
157:       end
association_reader(name, &make_association) click to toggle source
     # File lib/active_ldap/associations.rb, line 159
159:       def association_reader(name, &make_association)
160:         class_eval(          def #{name}            @#{name} ||= __make_#{name}          end, __FILE__, __LINE__ + 1)
161:       end
association_writer(name, &make_association) click to toggle source
     # File lib/active_ldap/associations.rb, line 167
167:       def association_writer(name, &make_association)
168:         class_eval(          def #{name}=(new_value)            association = defined?(@#{name}) ? @#{name} : nil            association ||= __make_#{name}            association.replace(new_value)            @#{name} = new_value.nil? ? nil : association            @#{name}          end, __FILE__, __LINE__ + 1)
169:       end
validate_belongs_to_options(options) click to toggle source
     # File lib/active_ldap/associations.rb, line 182
182:       def validate_belongs_to_options(options)
183:         options.assert_valid_keys(VALID_BELONGS_TO_OPTIONS)
184:       end
validate_has_many_options(options) click to toggle source
     # File lib/active_ldap/associations.rb, line 189
189:       def validate_has_many_options(options)
190:         options.assert_valid_keys(VALID_HAS_MANY_OPTIONS)
191:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.