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:
-
adds the instance method
xapian_id
to an indexed class
@author Gernot Kogler
Public Class Methods
Source
# 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
Implement the class helper methods @param [Class] klass The class to add the helper methods to
Calls superclass method
XapianDb::Adapters::BaseAdapter::add_class_helper_methods_to
Source
# File lib/xapian_db/adapters/generic_adapter.rb 44 def add_doc_helper_methods_to(obj) 45 # We have none so far 46 end
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
Source
# File lib/xapian_db/adapters/generic_adapter.rb 22 def unique_key(&block) 23 @unique_key_block = block 24 end
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