lib/active_ldap/associations.rb in activeldap-1.0.1 vs lib/active_ldap/associations.rb in activeldap-1.0.2

- old
+ new

@@ -29,11 +29,12 @@ # 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|. + # |: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 @@ -42,11 +43,12 @@ # :foreign_key => "gidNumber", # User#gidNumber # :primary_key => "gidNumber" # Group#gidNumber # def belongs_to(association_id, options={}) validate_belongs_to_options(options) - klass = options[:class] || association_id.to_s.classify + klass = options[:class] + klass ||= (options[:class_name] || association_id.to_s).classify foreign_key = options[:foreign_key] primary_key = options[:primary_key] many = options[:many] set_associated_class(association_id, klass) @@ -94,11 +96,12 @@ # :foreign_key => "gidNumber" # Group#gidNumber # has_many :members, :class_name => "User", # :wrap => "memberUid" # Group#memberUid def has_many(association_id, options = {}) validate_has_many_options(options) - klass = options[:class] || association_id.to_s.classify + klass = options[:class] + klass ||= (options[:class_name] || association_id.to_s).classify foreign_key = options[:foreign_key] || "#{association_id}_id" primary_key = options[:primary_key] set_associated_class(association_id, klass) opts = { @@ -147,16 +150,18 @@ @#{name} end EOM end - VALID_BELONGS_TO_OPTIONS = [:class, :foreign_key, :primary_key, :many, + VALID_BELONGS_TO_OPTIONS = [:class, :class_name, + :foreign_key, :primary_key, :many, :extend] def validate_belongs_to_options(options) options.assert_valid_keys(VALID_BELONGS_TO_OPTIONS) end - VALID_HAS_MANY_OPTIONS = [:class, :foreign_key, :primary_key, :wrap, + VALID_HAS_MANY_OPTIONS = [:class, :class_name, + :foreign_key, :primary_key, :wrap, :extend] def validate_has_many_options(options) options.assert_valid_keys(VALID_HAS_MANY_OPTIONS) end end