Class: Elastic::Core::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic/core/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefinition

Returns a new instance of Definition.



19
20
21
22
23
24
# File 'lib/elastic/core/definition.rb', line 19

def initialize
  @target = nil
  @field_map = {}
  @field_cache = {}
  @middleware_options = HashWithIndifferentAccess.new
end

Instance Attribute Details

#middleware_optionsObject (readonly)

Returns the value of attribute middleware_options.



3
4
5
# File 'lib/elastic/core/definition.rb', line 3

def middleware_options
  @middleware_options
end

Instance Method Details

#as_es_mappingObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/elastic/core/definition.rb', line 58

def as_es_mapping
  ensure_frozen!

  properties = {}
  @field_map.each_value do |field|
    properties[field.name] = field.mapping_options
  end

  { 'properties' => properties.as_json }
end

#fieldsObject



30
31
32
# File 'lib/elastic/core/definition.rb', line 30

def fields
  @field_map.each_value
end

#freezeObject



34
35
36
37
38
39
40
41
42
# File 'lib/elastic/core/definition.rb', line 34

def freeze
  return if frozen?

  cache_target
  complete_and_validate_fields
  freeze_fields
  @middleware_options.freeze
  super
end

#get_field(_name) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/elastic/core/definition.rb', line 44

def get_field(_name)
  ensure_frozen!

  _name = _name.to_s
  @field_cache[_name] = resolve_field(_name) unless @field_cache.key? _name
  @field_cache[_name]
end

#has_field?(_name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/elastic/core/definition.rb', line 52

def has_field?(_name)
  ensure_frozen!

  !get_field(_name).nil?
end

#modeObject



15
16
17
# File 'lib/elastic/core/definition.rb', line 15

def mode
  target.mode
end

#register_field(_field) ⇒ Object



26
27
28
# File 'lib/elastic/core/definition.rb', line 26

def register_field(_field)
  @field_map[_field.name] = _field
end

#targetObject



5
6
7
8
9
# File 'lib/elastic/core/definition.rb', line 5

def target
  raise 'attempting to access target before definition has been frozen' if @target_cache.nil?

  @target_cache
end

#target=(_value) ⇒ Object



11
12
13
# File 'lib/elastic/core/definition.rb', line 11

def target=(_value)
  @target = _value
end