class AgnosticBackend::Indexable::ContentManager

Public Instance Methods

add_definitions(&block) click to toggle source
# File lib/agnostic_backend/indexable/content_manager.rb, line 6
def add_definitions &block
  return unless block_given?
  instance_eval &block
end
contents() click to toggle source
# File lib/agnostic_backend/indexable/content_manager.rb, line 11
def contents
  @contents ||= {}
end
extract_contents_from(object, index_name, observer:) click to toggle source
# File lib/agnostic_backend/indexable/content_manager.rb, line 33
def extract_contents_from(object, index_name, observer:)
  kv_pairs = contents.map do |field_name, field|
    field_value = field.evaluate(context: object)
    if field.type.nested?
      if field_value.respond_to? :generate_document
        observer.add(field_value)
        field_value = field_value.generate_document(for_index: index_name, observer: observer)
      elsif field_value.present?
        field_name = nil
      end
    end
    [field_name, field_value]
  end
  kv_pairs.reject! { |attr_name, _| attr_name.nil? }
  Hash[kv_pairs]
end
field(field_name, value: nil, type:, from: nil, **options) click to toggle source
# File lib/agnostic_backend/indexable/content_manager.rb, line 28
def field(field_name, value: nil, type:, from: nil, **options)
  contents[field_name.to_s] = Field.new(value.present? ? value : field_name, type,
                                        from: from, **options)
end
method_missing(sym, *args, **kwargs) click to toggle source
Calls superclass method
# File lib/agnostic_backend/indexable/content_manager.rb, line 15
def method_missing(sym, *args, **kwargs)
  if FieldType.exists? sym
    kwargs[:type] = sym
    field(*args, **kwargs)
  else
    super
  end
end
respond_to?(sym, include_private=false) click to toggle source
Calls superclass method
# File lib/agnostic_backend/indexable/content_manager.rb, line 24
def respond_to?(sym, include_private=false)
  FieldType.exists?(sym) || super
end