generate_solr_document's yield breaks inheritability
ActiveFedora::IndexingService#generate_solr_document yields the solr_doc to a block, if given one, here. Specifically, it yields the doc AFTER adding all its data. So far, good enough.
The problem is that this class is expected to be extended and generate_solr_document is expected to be overriden, in all likelihood by a method that first calls super. ALL of ours downstream do (just like the to_solr's of old). But the overriding method must maintain the same signature and expectations as this one, namely:
- return the doc (hash)
- if given a block, should yield the same doc, i.e. AFTER adding all its data.
Our current extensions look like Hyrax::CollectionIndexer :
def generate_solr_document
super.tap do |solr_doc|
...
solr_doc['thumbnail_path_ss'] = thumbnail_path
...
end
end
But, because the yield happens inside the super call, here in ActiveFedora::IndexingService, the child class cannot call super AND later yield the fuller document. Instead, the block gets the primitive baseline document and our OO pattern is broken. thumbnail_path_ss is in the returned hash, but not the yielded one.
Yielding multiple times is NOT the method signature, so we cannot just throw in our own yield at the bottom of our tap or the method overall. super().tap does nothing to change block_given?, so that cannot be worked around. Since this is a core gem establishing patterns used throughout the ecosystem, we should be particularly conscious of proper OO inheritability.