Class: MongoMapper::Associations::Base
- Inherits:
-
Object
- Object
- MongoMapper::Associations::Base
- Defined in:
- lib/mongomapper/associations/base.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #class_name ⇒ Object
-
#initialize(type, name, options = {}) ⇒ Base
constructor
A new instance of Base.
- #ivar ⇒ Object
- #klass ⇒ Object
- #proxy_class ⇒ Object
Constructor Details
#initialize(type, name, options = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/mongomapper/associations/base.rb', line 6 def initialize(type, name, = {}) @options = @type = type @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/mongomapper/associations/base.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/mongomapper/associations/base.rb', line 4 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/mongomapper/associations/base.rb', line 4 def type @type end |
Instance Method Details
#class_name ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongomapper/associations/base.rb', line 16 def class_name @class_name ||= begin if cn = [:class_name] cn elsif @type == :many name.to_s.singularize.camelize else name.to_s.camelize end end end |
#ivar ⇒ Object
28 29 30 |
# File 'lib/mongomapper/associations/base.rb', line 28 def ivar @ivar ||= "@_#{name}" end |
#klass ⇒ Object
12 13 14 |
# File 'lib/mongomapper/associations/base.rb', line 12 def klass class_name.constantize end |
#proxy_class ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongomapper/associations/base.rb', line 32 def proxy_class case @type when :belongs_to if @options[:polymorphic] PolymorphicBelongsToProxy else BelongsToProxy end when :many if self.klass. if @options[:polymorphic] PolymorphicHasManyEmbeddedProxy else HasManyEmbeddedProxy end else HasManyProxy end end end |