Class: MongoMapper::Document::OrmAdapter

Inherits:
OrmAdapter::Base show all
Defined in:
lib/orm_adapter/adapters/mongo_mapper.rb

Instance Attribute Summary

Attributes inherited from OrmAdapter::Base

#klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OrmAdapter::Base

inherited, #initialize

Constructor Details

This class inherits a constructor from OrmAdapter::Base

Class Method Details

.except_classesObject

Do not consider these to be part of the class list



11
12
13
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 11

def self.except_classes
  @@except_classes ||= []
end

.model_classesObject

Gets a list of the available models for this adapter



16
17
18
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 16

def self.model_classes
  ObjectSpace.each_object(Class).to_a.select {|klass| klass.ancestors.include? MongoMapper::Document}
end

Instance Method Details

#column_namesObject

get a list of column names for a given class



21
22
23
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 21

def column_names
  klass.column_names
end

#create!(attributes = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#create!


50
51
52
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 50

def create!(attributes = {})
  klass.create!(attributes)
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


55
56
57
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 55

def destroy(object)
  object.destroy if valid_object?(object)
end

#find_all(conditions = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


43
44
45
46
47
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 43

def find_all(conditions = {})
  conditions, order = extract_conditions_and_order!(conditions)
  conditions = conditions.merge(:sort => order) unless order.nil?
  klass.all(conditions_to_fields(conditions))
end

#find_first(conditions = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


36
37
38
39
40
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 36

def find_first(conditions = {})
  conditions, order = extract_conditions_and_order!(conditions)
  conditions = conditions.merge(:sort => order) unless order.nil?
  klass.first(conditions_to_fields(conditions))
end

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


31
32
33
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 31

def get(id)
  klass.first({ :id => wrap_key(id) })
end

#get!(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get!


26
27
28
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 26

def get!(id)
  klass.find!(wrap_key(id))
end