Module: Elasticsearch::Model
- Extended by:
- ClassMethods
- Defined in:
- lib/elasticsearch/model.rb,
lib/elasticsearch/model/proxy.rb,
lib/elasticsearch/model/client.rb,
lib/elasticsearch/model/naming.rb,
lib/elasticsearch/model/adapter.rb,
lib/elasticsearch/model/version.rb,
lib/elasticsearch/model/indexing.rb,
lib/elasticsearch/model/response.rb,
lib/elasticsearch/model/callbacks.rb,
lib/elasticsearch/model/importing.rb,
lib/elasticsearch/model/searching.rb,
lib/elasticsearch/model/multimodel.rb,
lib/elasticsearch/model/serializing.rb,
lib/elasticsearch/model/response/base.rb,
lib/elasticsearch/model/response/result.rb,
lib/elasticsearch/model/adapters/default.rb,
lib/elasticsearch/model/adapters/mongoid.rb,
lib/elasticsearch/model/response/records.rb,
lib/elasticsearch/model/response/results.rb,
lib/elasticsearch/model/adapters/multiple.rb,
lib/elasticsearch/model/response/pagination.rb,
lib/elasticsearch/model/response/suggestions.rb,
lib/elasticsearch/model/response/aggregations.rb,
lib/elasticsearch/model/adapters/active_record.rb
Overview
Elasticsearch integration for Ruby models
‘Elasticsearch::Model` contains modules for integrating the Elasticsearch search and analytical engine with ActiveModel-based classes, or models, for the Ruby programming language.
It facilitates importing your data into an index, automatically updating it when a record changes, searching the specific index, setting up the index mapping or the model JSON serialization.
When the ‘Elasticsearch::Model` module is included in your class, it automatically extends it with the functionality; see Model.included. Most methods are available via the `__elasticsearch__` class and instance method proxies.
It is possible to include/extend the model with the corresponding modules directly, if that is desired:
MyModel.__send__ :extend, Elasticsearch::Model::Client::ClassMethods
MyModel.__send__ :include, Elasticsearch::Model::Client::InstanceMethods
MyModel.__send__ :extend, Elasticsearch::Model::Searching::ClassMethods
# ...
Defined Under Namespace
Modules: Adapter, Callbacks, ClassMethods, Client, Importing, Indexing, Naming, Proxy, Response, Searching, Serializing Classes: Multimodel, NotImplemented, Registry
Constant Summary collapse
- METHODS =
[:search, :mapping, :mappings, :settings, :index_name, :document_type, :import]
- VERSION =
"2.0.1"
Class Method Summary collapse
-
.included(base) ⇒ Object
Adds the ‘Elasticsearch::Model` functionality to the including class.
-
.settings ⇒ Object
Access the module settings.
Methods included from ClassMethods
client, client=, inheritance_enabled, inheritance_enabled=, search
Class Method Details
.included(base) ⇒ Object
Adds the ‘Elasticsearch::Model` functionality to the including class.
-
Creates the ‘__elasticsearch__` class and instance methods, pointing to the proxy object
-
Includes the necessary modules in the proxy classes
-
Sets up delegation for crucial methods such as ‘search`, etc.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/elasticsearch/model.rb', line 89 def self.included(base) base.class_eval do include Elasticsearch::Model::Proxy Elasticsearch::Model::Proxy::ClassMethodsProxy.class_eval do include Elasticsearch::Model::Client::ClassMethods include Elasticsearch::Model::Naming::ClassMethods include Elasticsearch::Model::Indexing::ClassMethods include Elasticsearch::Model::Searching::ClassMethods end Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval do include Elasticsearch::Model::Client::InstanceMethods include Elasticsearch::Model::Naming::InstanceMethods include Elasticsearch::Model::Indexing::InstanceMethods include Elasticsearch::Model::Serializing::InstanceMethods end Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval " def as_indexed_json(options={})\n target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super\n end\n CODE\n\n # Delegate important methods to the `__elasticsearch__` proxy, unless they are defined already\n #\n class << self\n METHODS.each do |method|\n delegate method, to: :__elasticsearch__ unless self.public_instance_methods.include?(method)\n end\n end\n\n # Mix the importing module into the proxy\n #\n self.__elasticsearch__.class_eval do\n include Elasticsearch::Model::Importing::ClassMethods\n include Adapter.from_class(base).importing_mixin\n end\n\n # Add to the registry if it's a class (and not in intermediate module)\n Registry.add(base) if base.is_a?(Class)\n end\nend\n", __FILE__, __LINE__ + 1 |
.settings ⇒ Object
Access the module settings
135 136 137 |
# File 'lib/elasticsearch/model.rb', line 135 def self.settings @settings ||= {} end |