lib/esse/index/settings.rb in esse-0.0.5 vs lib/esse/index/settings.rb in esse-0.1.1

- old
+ new

@@ -2,20 +2,19 @@ module Esse # https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-api/lib/elasticsearch/api/actions/indices/put_settings.rb class Index module ClassMethods - - def settings_hash(cluster_settings: true) - hash = cluster_settings ? cluster.index_settings.merge(setting.body) : setting.body + def settings_hash + hash = setting.body { Esse::SETTING_ROOT_KEY => (hash.key?(Esse::SETTING_ROOT_KEY) ? hash[Esse::SETTING_ROOT_KEY] : hash) } end # Define /_settings definition by each index. # # +hash+: The body of the request includes the updated settings. - # +block+: Overwrite default :as_json from IndexSetting instance + # +block+: Overwrite default :to_h from IndexSetting instance # # Example: # # class UserIndex < Esse::Index # settings { @@ -27,19 +26,19 @@ # settings do # # do something to load settings.. # end # end def settings(hash = {}, &block) - @setting = Esse::IndexSetting.new(body: hash, paths: template_dirs, globals: cluster.index_settings) - return unless block_given? + @setting = Esse::IndexSetting.new(body: hash, paths: template_dirs, globals: -> { cluster.index_settings }) + return unless block - @setting.define_singleton_method(:as_json, &block) + @setting.define_singleton_method(:to_h, &block) end private def setting - @setting ||= Esse::IndexSetting.new(paths: template_dirs, globals: cluster.index_settings) + @setting ||= Esse::IndexSetting.new(paths: template_dirs, globals: -> { cluster.index_settings }) end end extend ClassMethods end