Module: MarkMapper::Plugins::Associations::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#associationsObject


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

def associations
  @associations ||= {}
end

#associations=(hash) ⇒ Object


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

def associations=(hash)
  @embedded_associations = nil
  @associations = hash
end

#associations_moduleObject


48
49
50
51
52
53
54
55
56
57
# File 'lib/mark_mapper/plugins/associations.rb', line 48

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

#associations_module_defined?Boolean

Returns:


38
39
40
41
42
43
44
45
46
# File 'lib/mark_mapper/plugins/associations.rb', line 38

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

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


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

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

#embedded_associationsObject


34
35
36
# File 'lib/mark_mapper/plugins/associations.rb', line 34

def embedded_associations
  @embedded_associations ||= associations.values.select { |assoc| assoc.embeddable? }
end

#inherited(subclass) ⇒ Object


8
9
10
11
# File 'lib/mark_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/mark_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/mark_mapper/plugins/associations.rb', line 21

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