Class: Esse::IndexSetting

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/index_setting.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(body: {}, paths: [], globals: nil) ⇒ IndexSetting

Returns a new instance of IndexSetting.

Parameters:

  • options (Hash)


10
11
12
13
14
# File 'lib/esse/index_setting.rb', line 10

def initialize(body: {}, paths: [], globals: nil)
  @globals = globals || -> { {} }
  @paths = Array(paths)
  @settings = body
end

Instance Method Details

#bodyObject



32
33
34
35
36
# File 'lib/esse/index_setting.rb', line 32

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

#to_hObject

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


26
27
28
29
30
# File 'lib/esse/index_setting.rb', line 26

def to_h
  return @settings unless @settings.empty?

  from_template || @settings
end