Class: ActsAsFerret::RemoteIndex

Inherits:
AbstractIndex show all
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

Methods inherited from AbstractIndex

#change_index_dir, #shared?

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, options = {}, &proc)
  total_hits, results = handle_drb_error([0, []]) { @server.find_ids(index_name, q, options) }
  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, options)
  handle_drb_error { @server.register_class clazz.name }
end