Sha256: d4d471b96b98ba87de83f0c559cfe637c80579ef87c2bd6121a14b6b70e524c1
Contents?: true
Size: 1.51 KB
Versions: 16
Compression:
Stored size: 1.51 KB
Contents
module MongoMapper module Associations class Base attr_reader :type, :name, :options def initialize(type, name, options = {}) @type, @name, @options = type, name, options end def class_name @class_name ||= begin if cn = options[:class_name] cn elsif many? name.to_s.singularize.camelize else name.to_s.camelize end end end def klass @klass ||= class_name.constantize end def many? @many_type ||= @type == :many end def belongs_to? @belongs_to_type ||= @type == :belongs_to end def polymorphic? !!@options[:polymorphic] end def type_key_name @type_key_name ||= many? ? '_type' : "#{name}_type" end def foreign_key @options[:foreign_key] || "#{name}_id" end def ivar @ivar ||= "@_#{name}" end def embeddable? many? && klass.embeddable? end def proxy_class @proxy_class ||= begin if many? if self.klass.embeddable? polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy else polymorphic? ? ManyPolymorphicProxy : ManyProxy end else polymorphic? ? BelongsToPolymorphicProxy : BelongsToProxy end end # end begin end # end proxy_class end end end
Version data entries
16 entries across 16 versions & 4 rubygems