Class: Machinist::MongoMapperAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/machinist/mongomapper.rb

Class Method Summary collapse

Class Method Details

.assigned_attributes_without_associations(lathe) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/machinist/mongomapper.rb', line 16

def self.assigned_attributes_without_associations(lathe)
  attributes = {}
  lathe.assigned_attributes.each_pair do |attribute, value|
    association = lathe.object.class.associations[attribute]
    if association && association.belongs_to?
      attributes[association.foreign_key.to_sym] = value.id
    else
      attributes[attribute] = value
    end
  end
  attributes
end

.class_for_association(object, attribute) ⇒ Object



11
12
13
14
# File 'lib/machinist/mongomapper.rb', line 11

def self.class_for_association(object, attribute)
  association = object.class.associations[attribute]
  association && association.klass
end

.has_association?(object, attribute) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/machinist/mongomapper.rb', line 7

def self.has_association?(object, attribute)
  object.class.associations[attribute]
end