Sha256: 728f5a529899af4654bc4ba2c4bbbc50de30489b1cd5abde6b6cdece479518f7

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Esse
  # https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices.html
  class IndexSetting
    # @param [Hash] options
    # @option options [Proc] :globals  A proc that will be called to load global settings
    # @option options [Array] :paths   A list of paths to load settings from
    # @option options [Hash]  :body    A hash of settings to override
    def initialize(body: {}, paths: [], globals: nil)
      @globals = globals || -> { {} }
      @paths = Array(paths)
      @settings = body
    end

    # This method will be overwrited when passing a block during the settings
    # defination on index class.
    #
    # Example:
    #   class UserIndex < Esse::Index
    #     settings do
    #       # do something to load settings..
    #     end
    #   end
    #
    def to_h
      return @settings unless @settings.empty?

      from_template || @settings
    end

    def body
      global = HashUtils.deep_transform_keys(@globals.call, &:to_sym)
      local = HashUtils.deep_transform_keys(to_h, &:to_sym)
      HashUtils.deep_merge(global, local)
    end

    protected

    def from_template
      return if @paths.empty?

      loader = Esse::TemplateLoader.new(@paths)
      loader.read('{setting,settings}')
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
esse-0.4.0.rc4 lib/esse/index_setting.rb
esse-0.4.0.rc3 lib/esse/index_setting.rb
esse-0.4.0.rc2 lib/esse/index_setting.rb
esse-0.4.0.rc1 lib/esse/index_setting.rb
esse-0.3.5 lib/esse/index_setting.rb
esse-0.3.4 lib/esse/index_setting.rb
esse-0.3.3 lib/esse/index_setting.rb
esse-0.3.2 lib/esse/index_setting.rb
esse-0.3.1 lib/esse/index_setting.rb
esse-0.3.0 lib/esse/index_setting.rb
esse-0.2.6 lib/esse/index_setting.rb
esse-0.2.5 lib/esse/index_setting.rb
esse-0.2.4 lib/esse/index_setting.rb
esse-0.2.3 lib/esse/index_setting.rb
esse-0.2.2 lib/esse/index_setting.rb