@@ -153,7 +153,8 @@ def mapping(options={}, &block)
153
153
#
154
154
# # => {:index=>{:number_of_shards=>1}}
155
155
#
156
- # You can specify a YAML file with settings
156
+ # You can read settings from any object that responds to :read
157
+ # as long as its return value can be parsed as either YAML or JSON.
157
158
#
158
159
# @example Define index settings from YAML file
159
160
#
@@ -163,14 +164,28 @@ def mapping(options={}, &block)
163
164
# # number_of_shards: 1
164
165
# #
165
166
#
166
- # Article.settings "config/elasticsearch/articles.yml"
167
+ # Article.settings File.open("config/elasticsearch/articles.yml")
168
+ #
169
+ # Article.settings.to_hash
170
+ #
171
+ # # => { "index" => { "number_of_shards" => 1 } }
172
+ #
173
+ #
174
+ # @example Define index settings from JSON file
175
+ #
176
+ # # config/elasticsearch/articles.json:
177
+ # #
178
+ # # { "index": { "number_of_shards": 1 } }
179
+ # #
180
+ #
181
+ # Article.settings File.open("config/elasticsearch/articles.json")
167
182
#
168
183
# Article.settings.to_hash
169
184
#
170
185
# # => { "index" => { "number_of_shards" => 1 } }
171
186
#
172
187
def settings ( settings = { } , &block )
173
- settings = YAML . load_file ( settings ) if settings . is_a? ( String )
188
+ settings = YAML . load ( settings . read ) if settings . respond_to? ( :read )
174
189
@settings ||= Settings . new ( settings )
175
190
176
191
@settings . settings . update ( settings ) unless settings . empty?
@@ -183,6 +198,10 @@ def settings(settings={}, &block)
183
198
end
184
199
end
185
200
201
+ def load_settings_from_io ( settings )
202
+ YAML . load ( settings . read )
203
+ end
204
+
186
205
# Creates an index with correct name, automatically passing
187
206
# `settings` and `mappings` defined in the model
188
207
#
0 commit comments