Sha256: 3b361f7506644228081d93ff7d8a7100294716b8c4adcb833b17d883864b03a9
Contents?: true
Size: 2 KB
Versions: 20
Compression:
Stored size: 2 KB
Contents
module Sunspot #:nodoc: module MongoMapper #:nodoc: # # This module provides Sunspot Adapter implementations for MongoMapper # models. # module Adapters class MongoMapperInstanceAdapter < Sunspot::Adapters::InstanceAdapter # # Return the primary key for the adapted instance # # ==== Returns # # Integer:: Database ID of model # def id @instance.id end end class MongoMapperDataAccessor < Sunspot::Adapters::DataAccessor # options for the find attr_accessor :include, :select # # Set the fields to select from the database. This will be passed # to MongoMapper. # # ==== Parameters # # value<Mixed>:: String of comma-separated columns or array of columns # def select=(value) value = value.join(', ') if value.respond_to?(:join) @select = value end # # Get one MongoMapper instance out of the database by ID # # ==== Parameters # # id<String>:: Database ID of model to retreive # # ==== Returns # # MongoMapper::Base:: MongoMapper model # def load(id) @clazz.first(options_for_find.merge(:id => id)) end # # Get a collection of MongoMapper instances out of the database by ID # # ==== Parameters # # ids<Array>:: Database IDs of models to retrieve # # ==== Returns # # Array:: Collection of MongoMapper models # def load_all(ids) @clazz.all(options_for_find.merge(:id => ids)) end private def options_for_find returning({}) do |options| options[:include] = @include unless @include.blank? options[:select] = @select unless @select.blank? end end end end end end
Version data entries
20 entries across 20 versions & 2 rubygems