class XapianDb::Adapters::GenericAdapter

The generic adapter is a universal adapater that can be used for any ruby class. To use the generic adapter (which is the default), configure the expression that generates a unique key from your objects using the method ‘unique_key’. This adapter does the following:

@author Gernot Kogler

Public Class Methods

add_class_helper_methods_to(klass) click to toggle source

Implement the class helper methods @param [Class] klass The class to add the helper methods to

   # File lib/xapian_db/adapters/generic_adapter.rb
28 def add_class_helper_methods_to(klass)
29   raise "Unique key is not configured for generic adapter!" if @unique_key_block.nil?
30 
31   # Add the helpers from the base class
32   super klass
33 
34   expression = @unique_key_block
35   klass.instance_eval do
36     define_method(:xapian_id) do
37       instance_eval &expression
38     end
39   end
40 end
add_doc_helper_methods_to(obj) click to toggle source

Implement the document helper methods on a module. So far there are none @param [Module] a_module The module to add the helper methods to

   # File lib/xapian_db/adapters/generic_adapter.rb
44 def add_doc_helper_methods_to(obj)
45   # We have none so far
46 end
unique_key(&block) click to toggle source

Define the unique key expression @example Use the same unique expression like the active record adapter (assuming your objects have an id)

XapianDb::Adapters::GenericAdapter.unique_key do
  "#{self.class}-#{self.id}"
end
   # File lib/xapian_db/adapters/generic_adapter.rb
22 def unique_key(&block)
23   @unique_key_block = block
24 end