module MarkMapper::Plugins::Associations::ClassMethods
Public Instance Methods
associations()
click to toggle source
# File lib/mark_mapper/plugins/associations.rb, line 25 def associations @associations ||= {} end
associations=(hash)
click to toggle source
# File lib/mark_mapper/plugins/associations.rb, line 29 def associations=(hash) @embedded_associations = nil @associations = hash end
associations_module()
click to toggle source
# 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?()
click to toggle source
# 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)
click to toggle source
# 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_associations()
click to toggle source
# File lib/mark_mapper/plugins/associations.rb, line 34 def embedded_associations @embedded_associations ||= associations.values.select { |assoc| assoc.embeddable? } end
inherited(subclass)
click to toggle source
Calls superclass method
# File lib/mark_mapper/plugins/associations.rb, line 8 def inherited(subclass) subclass.associations = associations.dup super end
many(association_id, options={}, &extension)
click to toggle source
# 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)
click to toggle source
# File lib/mark_mapper/plugins/associations.rb, line 21 def one(association_id, options={}, &extension) create_association(OneAssociation.new(association_id, options, &extension)) end
Private Instance Methods
create_association(association)
click to toggle source
# File lib/mark_mapper/plugins/associations.rb, line 60 def create_association(association) @embedded_associations = nil associations[association.name] = association association.setup(self) end