@@ -35,7 +35,23 @@ module Elasticsearch
35
35
# Elasticsearch integration for Ruby models
36
36
# =========================================
37
37
#
38
- # TODO: Description
38
+ # `Elasticsearch::Model` contains modules for integrating the Elasticsearch search and analytical engine
39
+ # with ActiveModel-based classes, or models, for the Ruby programming language.
40
+ #
41
+ # It facilitates importing your data into an index, automatically updating it when a record changes,
42
+ # searching the specific index, setting up the index mapping or the model JSON serialization.
43
+ #
44
+ # When the `Elasticsearch::Model` module is included in your class, it automatically extends it
45
+ # with the functionality; see {Elasticsearch::Model.included}. Most methods are available via
46
+ # the `__elasticsearch__` class and instance method proxies.
47
+ #
48
+ # It is possible to include/extend the model with the corresponding
49
+ # modules directly, if that is desired:
50
+ #
51
+ # MyModel.__send__ :extend, Elasticsearch::Model::Client::ClassMethods
52
+ # MyModel.__send__ :include, Elasticsearch::Model::Client::InstanceMethods
53
+ # MyModel.__send__ :extend, Elasticsearch::Model::Searching::ClassMethods
54
+ # # ...
39
55
#
40
56
module Model
41
57
@@ -45,23 +61,16 @@ module Model
45
61
# * Includes the necessary modules in the proxy classes
46
62
# * Sets up delegation for crucial methods such as `search`, etc.
47
63
#
48
- # @example Include the {Elasticsearch::Model} module in the `Article` model definition
64
+ # @example Include the module in the `Article` model definition
49
65
#
50
66
# class Article < ActiveRecord::Base
51
67
# include Elasticsearch::Model
52
68
# end
53
69
#
54
- # @example Inject the {Elasticsearch::Model} module into the `Article` model
70
+ # @example Inject the module into the `Article` model during run time
55
71
#
56
72
# Article.__send__ :include, Elasticsearch::Model
57
73
#
58
- # It is possible to include/extend the model with the corresponding
59
- # modules directly, without using the proxy, if this is desired:
60
- #
61
- # MyModel.__send__ :extend, Elasticsearch::Model::Client::ClassMethods
62
- # MyModel.__send__ :include, Elasticsearch::Model::Client::InstanceMethods
63
- # MyModel.__send__ :extend, Elasticsearch::Model::Searching::ClassMethods
64
- # # ...
65
74
#
66
75
def self . included ( base )
67
76
base . class_eval do
@@ -100,6 +109,19 @@ module ClassMethods
100
109
101
110
# Get or set the client for all models
102
111
#
112
+ # @example Get the client
113
+ #
114
+ # Elasticsearch::Model.client
115
+ # => #<Elasticsearch::Transport::Client:0x007f96a7d0d000 @transport=... >
116
+ #
117
+ # @example Configure (set) the client for all the models
118
+ #
119
+ # Elasticsearch::Model.client Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
120
+ # => #<Elasticsearch::Transport::Client:0x007f96a6dd0d80 @transport=... >
121
+ #
122
+ # @note You have to set the client before you call Elasticsearch methods on the model,
123
+ # or set it directly on the model; see {Elasticsearch::Model::Client::ClassMethods#client}
124
+ #
103
125
def client client = nil
104
126
@client = client || @client || Elasticsearch ::Client . new
105
127
end
0 commit comments