Class: Elastic::Core::Serializer

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

Direct Known Subclasses

Types::BaseType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_definition, _object) ⇒ Serializer

Returns a new instance of Serializer.



9
10
11
12
13
# File 'lib/elastic/core/serializer.rb', line 9

def initialize(_definition, _object)
  # TODO: validate that object is of type <target>?
  @definition = _definition
  @object = _object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

Class Method Details

.original_value_occluded?(_field) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/elastic/core/serializer.rb', line 5

def self.original_value_occluded?(_field)
  public_method_defined? _field
end

Instance Method Details

#as_elastic_document(only_meta: false) ⇒ Object



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

def as_elastic_document(only_meta: false)
  result = {}
  result['_id'] = read_attribute_for_indexing(:id) if has_attribute_for_indexing?(:id)
  result['data'] = as_elastic_source unless only_meta
  result
end

#as_elastic_sourceObject



26
27
28
29
30
31
32
33
34
# File 'lib/elastic/core/serializer.rb', line 26

def as_elastic_source
  {}.tap do |hash|
    fields.each do |field|
      value = read_attribute_for_indexing(field.name)
      value = field.prepare_value_for_index(value)
      hash[field.name] = value
    end
  end
end

#fieldsObject



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

def fields
  @definition.fields
end