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

Instance Method Summary collapse

Methods inherited from OrmAdapter::Base

inherited, #initialize

Constructor Details

This class inherits a constructor from OrmAdapter::Base

Instance Method Details

#column_namesObject

get a list of column names for a given class



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

def column_names
  klass.column_names
end

#create!(attributes = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#create!


42
43
44
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 42

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

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


47
48
49
# File 'lib/orm_adapter/adapters/mongo_mapper.rb', line 47

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

#find_all(conditions = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


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

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

#find_first(conditions = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


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

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

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


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

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

#get!(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get!


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

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