Module: MongoMapper::Plugins::Associations::ClassMethods

Defined in:
lib/mongo_mapper/plugins/associations.rb

Instance Method Summary collapse

Instance Method Details

#associationsObject



25
26
27
# File 'lib/mongo_mapper/plugins/associations.rb', line 25

def associations
  @associations ||= {}
end

#associations=(hash) ⇒ Object



29
30
31
# File 'lib/mongo_mapper/plugins/associations.rb', line 29

def associations=(hash)
  @associations = hash
end

#associations_moduleObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/mongo_mapper/plugins/associations.rb', line 41

def associations_module
  if associations_module_defined?
    const_get 'MongoMapperAssociations'
  else
    Module.new.tap do |m|
      const_set 'MongoMapperAssociations', m
      include m
    end
  end
end

#associations_module_defined?Boolean

Returns:



33
34
35
36
37
38
39
# File 'lib/mongo_mapper/plugins/associations.rb', line 33

def associations_module_defined?
  if method(:const_defined?).arity == 1 # Ruby 1.9 compat check
    const_defined?('MongoMapperAssociations')
  else
    const_defined?('MongoMapperAssociations', false)
  end
end

#belongs_to(association_id, options = {}, &extension) ⇒ Object



13
14
15
# File 'lib/mongo_mapper/plugins/associations.rb', line 13

def belongs_to(association_id, options={}, &extension)
  create_association(BelongsToAssociation.new(association_id, options, &extension))
end

#inherited(subclass) ⇒ Object



8
9
10
11
# File 'lib/mongo_mapper/plugins/associations.rb', line 8

def inherited(subclass)
  subclass.associations = associations.dup
  super
end

#many(association_id, options = {}, &extension) ⇒ Object



17
18
19
# File 'lib/mongo_mapper/plugins/associations.rb', line 17

def many(association_id, options={}, &extension)
  create_association(ManyAssociation.new(association_id, options, &extension))
end

#one(association_id, options = {}, &extension) ⇒ Object



21
22
23
# File 'lib/mongo_mapper/plugins/associations.rb', line 21

def one(association_id, options={}, &extension)
  create_association(OneAssociation.new(association_id, options, &extension))
end