17
17
18
18
module Elasticsearch
19
19
module Model
20
-
21
- # Provides methods for getting and setting index name and document type for the model
20
+ # Provides methods for getting and setting index name the model
22
21
#
23
22
module Naming
24
-
25
- DEFAULT_DOC_TYPE = '_doc' . freeze
26
-
27
23
module ClassMethods
28
-
29
24
# Get or set the name of the index
30
25
#
31
26
# @example Set the index name for the `Article` model
@@ -64,46 +59,18 @@ def index_name=(name)
64
59
@index_name = name
65
60
end
66
61
67
- # Get or set the document type
68
- #
69
- # @example Set the document type for the `Article` model
70
- #
71
- # class Article
72
- # document_type "my-article"
73
- # end
74
- #
75
- # @example Directly set the document type for the `Article` model
76
- #
77
- # Article.document_type "my-article"
78
- #
79
- def document_type name = nil
80
- @document_type = name || @document_type || implicit ( :document_type )
81
- end
82
-
83
-
84
- # Set the document type
85
- #
86
- # @see document_type
87
- #
88
- def document_type = ( name )
89
- @document_type = name
90
- end
91
-
92
62
private
93
63
94
- def implicit ( prop )
95
- self . send ( "default_#{ prop } " )
96
- end
97
-
98
- def default_index_name
99
- self . model_name . collection . gsub ( /\/ / , '-' )
100
- end
64
+ def implicit ( prop )
65
+ self . send ( "default_#{ prop } " )
66
+ end
101
67
102
- def default_document_type ; end
68
+ def default_index_name
69
+ self . model_name . collection . gsub ( /\/ / , '-' )
70
+ end
103
71
end
104
72
105
73
module InstanceMethods
106
-
107
74
# Get or set the index name for the model instance
108
75
#
109
76
# @example Set the index name for an instance of the `Article` model
@@ -129,25 +96,7 @@ def index_name name=nil, &block
129
96
def index_name = ( name )
130
97
@index_name = name
131
98
end
132
-
133
- # @example Set the document type for an instance of the `Article` model
134
- #
135
- # @article.document_type "my-article"
136
- # @article.__elasticsearch__.update_document
137
- #
138
- def document_type name = nil
139
- @document_type = name || @document_type || self . class . document_type
140
- end
141
-
142
- # Set the document type
143
- #
144
- # @see document_type
145
- #
146
- def document_type = ( name )
147
- @document_type = name
148
- end
149
99
end
150
-
151
100
end
152
101
end
153
102
end
0 commit comments