Class: Elastic::Core::Serializer
- Inherits:
-
Object
- Object
- Elastic::Core::Serializer
- Defined in:
- lib/elastic/core/serializer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
- #as_elastic_document(only_meta: false) ⇒ Object
- #as_elastic_source ⇒ Object
- #fields ⇒ Object
-
#initialize(_definition, _object) ⇒ Serializer
constructor
A new instance of Serializer.
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
#object ⇒ Object (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
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 result end |
#as_elastic_source ⇒ Object
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 |
#fields ⇒ Object
15 16 17 |
# File 'lib/elastic/core/serializer.rb', line 15 def fields @definition.fields end |