Sha256: f30900f8ac46edce0959e70159226e7c5a6a80f3335943623e9b500eaf16272a

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

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
        { 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
      #
      # Example:
      #
      #   class UserIndex < Esse::Index
      #     settings {
      #       number_of_replicas: 4,
      #     }
      #   end
      #
      #   class UserIndex < Esse::Index
      #     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.define_singleton_method(:as_json, &block)
      end

      private

      def setting
        @setting ||= Esse::IndexSetting.new(paths: template_dirs, globals: cluster.index_settings)
      end
    end

    extend ClassMethods
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
esse-0.0.5 lib/esse/index/settings.rb
esse-0.0.4 lib/esse/index/settings.rb
esse-0.0.3 lib/esse/index/settings.rb