File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed
elasticsearch-model/lib/elasticsearch Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,12 @@ def self.included(base)
90
90
include Elasticsearch ::Model ::Serializing ::InstanceMethods
91
91
end
92
92
93
+ Elasticsearch ::Model ::Proxy ::InstanceMethodsProxy . class_eval <<-CODE , __FILE__ , __LINE__ + 1
94
+ def as_indexed_json(options={})
95
+ target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super
96
+ end
97
+ CODE
98
+
93
99
# Delegate important methods to the `__elasticsearch__` proxy, unless they are defined already
94
100
#
95
101
extend Support ::Forwardable
@@ -101,11 +107,6 @@ def self.included(base)
101
107
forward :'self.__elasticsearch__' , :document_type unless respond_to? ( :document_type )
102
108
forward :'self.__elasticsearch__' , :import unless respond_to? ( :import )
103
109
104
- instance_delegate [ :as_indexed_json ] => :__elasticsearch__
105
- instance_delegate [ :index_document ] => :__elasticsearch__
106
- instance_delegate [ :update_document ] => :__elasticsearch__
107
- instance_delegate [ :delete_document ] => :__elasticsearch__
108
-
109
110
# Mix the importing module into the proxy
110
111
#
111
112
self . __elasticsearch__ . class . __send__ :include , Elasticsearch ::Model ::Importing ::ClassMethods
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ module Model
21
21
#
22
22
# article = Article.first
23
23
#
24
- # article.respond_to? :as_indexed_json
24
+ # article.respond_to? :index_document
25
25
# # => false
26
26
#
27
- # article.__elasticsearch__.respond_to?(:as_indexed_json )
27
+ # article.__elasticsearch__.respond_to?(:index_document )
28
28
# # => true
29
29
#
30
30
module Proxy
Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ module InstanceMethods
12
12
13
13
# Serialize the record as a Hash, to be passed to the client.
14
14
#
15
+ # Re-define this method to customize the serialization.
16
+ #
15
17
# @return [Hash]
16
18
#
17
- # @example
19
+ # @example Return the model instance as a Hash
18
20
#
19
- # Article.first.__elasticsearch__.as_indexed_json(only: 'title')
21
+ # Article.first.__elasticsearch__.as_indexed_json
20
22
# => {"title"=>"Foo"}
21
23
#
22
24
# @see Elasticsearch::Model::Indexing
You can’t perform that action at this time.
0 commit comments