class Elastic::Core::Serializer
Attributes
object[R]
Public Class Methods
new(_definition, _object)
click to toggle source
# 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
original_value_occluded?(_field)
click to toggle source
# File lib/elastic/core/serializer.rb, line 5 def self.original_value_occluded?(_field) public_method_defined? _field end
Public Instance Methods
as_elastic_document(only_meta: false)
click to toggle source
# 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_source()
click to toggle source
# 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
fields()
click to toggle source
# File lib/elastic/core/serializer.rb, line 15 def fields @definition.fields end
Private Instance Methods
has_attribute_for_indexing?(_name)
click to toggle source
# File lib/elastic/core/serializer.rb, line 38 def has_attribute_for_indexing?(_name) respond_to?(_name) || @object.respond_to?(_name) end
read_attribute_for_indexing(_name)
click to toggle source
# File lib/elastic/core/serializer.rb, line 42 def read_attribute_for_indexing(_name) respond_to?(_name) ? public_send(_name) : @object.public_send(_name) end