Class: XapianDb::Adapters::GenericAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- XapianDb::Adapters::GenericAdapter
- Defined in:
- lib/xapian_db/adapters/generic_adapter.rb
Overview
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
Class Method Summary collapse
-
.add_class_helper_methods_to(klass) ⇒ Object
Implement the class helper methods.
-
.add_doc_helper_methods_to(obj) ⇒ Object
Implement the document helper methods on a module.
-
.unique_key(&block) ⇒ Object
Define the unique key expression.
Class Method Details
.add_class_helper_methods_to(klass) ⇒ Object
Implement the class helper methods
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xapian_db/adapters/generic_adapter.rb', line 28 def add_class_helper_methods_to(klass) raise "Unique key is not configured for generic adapter!" if @unique_key_block.nil? # Add the helpers from the base class super klass expression = @unique_key_block klass.instance_eval do define_method(:xapian_id) do instance_eval &expression end end end |
.add_doc_helper_methods_to(obj) ⇒ Object
Implement the document helper methods on a module. So far there are none
44 45 46 |
# File 'lib/xapian_db/adapters/generic_adapter.rb', line 44 def add_doc_helper_methods_to(obj) # We have none so far end |
.unique_key(&block) ⇒ Object
Define the unique key expression
22 23 24 |
# File 'lib/xapian_db/adapters/generic_adapter.rb', line 22 def unique_key(&block) @unique_key_block = block end |