Skip to content

Instantly share code, notes, and snippets.

@stackdump
Created May 9, 2015 14:38
Show Gist options
  • Save stackdump/0e5b3a2764cffa535116 to your computer and use it in GitHub Desktop.
Save stackdump/0e5b3a2764cffa535116 to your computer and use it in GitHub Desktop.
# == Examples:
#
# class Post < ActiveRecord::Base
#
# include Sunspot::Document
#
# searchable do
# text :title
# end
# end
#
module Sunspot
module Document
def self.included(base)
base.class_eval do
extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
end
end
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
criteria(id).first
end
def load_all(ids)
criteria(ids)
end
private
def criteria(id)
@clazz.find(id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment