Class: Esse::IndexMapping

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

Constant Summary collapse

FILENAMES =
%w[mapping mappings].freeze

Instance Method Summary collapse

Constructor Details

#initialize(body: {}, paths: [], filenames: FILENAMES, globals: nil) ⇒ IndexMapping

Returns a new instance of IndexMapping.



7
8
9
10
11
12
# File 'lib/esse/index_mapping.rb', line 7

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

Instance Method Details

#bodyObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/esse/index_mapping.rb', line 22

def body
  global = HashUtils.deep_transform_keys(@globals.call, &:to_sym)
  local = HashUtils.deep_transform_keys(to_h.dup, &:to_sym)
  dynamic_template = DynamicTemplate.new(global[:dynamic_templates])
  dynamic_template.merge!(local.delete(:dynamic_templates))
  if dynamic_template.any?
    global[:dynamic_templates] = dynamic_template.to_a
  end
  HashUtils.deep_merge(global, local)
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/esse/index_mapping.rb', line 33

def empty?
  body.empty?
end

#to_hObject

This method will be overwrited when passing a block during the mapping defination



16
17
18
19
20
# File 'lib/esse/index_mapping.rb', line 16

def to_h
  return @mappings unless @mappings.empty?

  from_template || @mappings
end