MongoMapper::Document::OrmAdapter

Public Instance Methods

column_names() click to toggle source

get a list of column names for a given class

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 11
def column_names
  klass.column_names
end
create!(attributes = {}) click to toggle source

@see OrmAdapter::Base#create!

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 42
def create!(attributes = {})
  klass.create!(attributes)
end
destroy(object) click to toggle source

@see OrmAdapter::Base#destroy

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 47
def destroy(object)
  object.destroy if valid_object?(object)
end
find_all(conditions = {}) click to toggle source

@see OrmAdapter::Base#find_all

# 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 = {}) click to toggle source

@see OrmAdapter::Base#find_first

# 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) click to toggle source

@see OrmAdapter::Base#get

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 21
def get(id)
  klass.first({ :id => wrap_key(id) })
end
get!(id) click to toggle source

@see OrmAdapter::Base#get!

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 16
def get!(id)
  klass.find!(wrap_key(id))
end

Protected Instance Methods

conditions_to_fields(conditions) click to toggle source

converts and documents to ids

# File lib/orm_adapter/adapters/mongo_mapper.rb, line 54
def conditions_to_fields(conditions)
  conditions.inject({}) do |fields, (key, value)|
    if value.is_a?(MongoMapper::Document) && klass.key?("#{key}_id")
      fields.merge("#{key}_id" => value.id)
    else
      fields.merge(key => value)
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.