Class: ActsAsFerret::RemoteIndex
- Inherits:
-
AbstractIndex
- Object
- AbstractIndex
- ActsAsFerret::RemoteIndex
- Includes:
- RemoteFunctions
- Defined in:
- lib/acts_as_ferret/remote_index.rb
Overview
This index implementation connects to a remote ferret server instance. It basically forwards all calls to the remote server.
Instance Attribute Summary
Attributes inherited from AbstractIndex
#index_definition, #index_name, #logger, #registered_models_config
Instance Method Summary collapse
-
#add(record) ⇒ Object
(also: #<<)
add record to index.
- #find_ids(q, options = {}, &proc) ⇒ Object
-
#initialize(config) ⇒ RemoteIndex
constructor
A new instance of RemoteIndex.
- #method_missing(method_name, *args) ⇒ Object
-
#register_class(clazz, options) ⇒ Object
Cause model classes to be loaded (and indexes get declared) on the DRb side of things.
Methods inherited from AbstractIndex
Methods included from FerretFindMethods
#ar_find, #count_records, #find_id_model_arrays, #find_records, #lazy_find, #scope_query_to_models
Constructor Details
#initialize(config) ⇒ RemoteIndex
Returns a new instance of RemoteIndex.
9 10 11 12 |
# File 'lib/acts_as_ferret/remote_index.rb', line 9 def initialize(config) super @server = DRbObject.new(nil, ActsAsFerret::remote) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
20 21 22 23 |
# File 'lib/acts_as_ferret/remote_index.rb', line 20 def method_missing(method_name, *args) args.unshift index_name handle_drb_error { @server.send(method_name, *args) } end |
Instance Method Details
#add(record) ⇒ Object Also known as: <<
add record to index
41 42 43 |
# File 'lib/acts_as_ferret/remote_index.rb', line 41 def add(record) handle_drb_error { @server.add index_name, record.to_doc } end |
#find_ids(q, options = {}, &proc) ⇒ Object
35 36 37 38 |
# File 'lib/acts_as_ferret/remote_index.rb', line 35 def find_ids(q, = {}, &proc) total_hits, results = handle_drb_error([0, []]) { @server.find_ids(index_name, q, ) } block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ] end |
#register_class(clazz, options) ⇒ Object
Cause model classes to be loaded (and indexes get declared) on the DRb side of things.
16 17 18 |
# File 'lib/acts_as_ferret/remote_index.rb', line 16 def register_class(clazz, ) handle_drb_error { @server.register_class clazz.name } end |