Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/xapit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ def symbolize_keys(arg)
require 'xapit/client/model_adapters/abstract_model_adapter'
require 'xapit/client/model_adapters/default_model_adapter'
require 'xapit/client/model_adapters/active_record_adapter'
require 'xapit/client/model_adapters/mongoid_adapter'
2 changes: 1 addition & 1 deletion lib/xapit/client/model_adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Xapit
module Client
class ActiveRecordAdapter < AbstractModelAdapter
def self.for_class?(model_class)
model_class <= ActiveRecord::Base
defined?(ActiveRecord::Base) && model_class <= ActiveRecord::Base
end

def setup
Expand Down
32 changes: 32 additions & 0 deletions lib/xapit/client/model_adapters/mongoid_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Xapit
module Client
class MongoidAdapter < AbstractModelAdapter
def self.for_class?(model_class)
defined?(Mongoid::Document) && model_class <= Mongoid::Document
end

def setup
@model_class.after_create do |member|
member.class.xapit_index_builder.add_document(member) if Xapit.config[:enabled]
end
@model_class.after_update do |member|
member.class.xapit_index_builder.update_document(member) if Xapit.config[:enabled]
end
@model_class.after_destroy do |member|
member.class.xapit_index_builder.remove_document(member) if Xapit.config[:enabled]
end
end

def index_all
@model_class.all.each do |member|
member.class.xapit_index_builder.add_document(member)
end
end
end
end
end

if defined?(Mongoid::Document)
Mongoid::Document::ClassMethods.send(:include, Xapit::Client::Membership::ClassMethods)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? I want those methods available on sinatra too, that's not rails exclusive

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, then is a good idea move the AR one to active_record_adapter.rb

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then is a good idea move the AR one to the adapter also :)

end