From a1517e10d2818272e48b55e9ebd2dbc4ae7e1209 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Fri, 29 Mar 2024 13:57:11 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Favor=20method=5Fmissing?= =?UTF-8?q?=20over=20a=20raft=20of=20delegates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's like we're flooding a political convention with delegates. Instead of having all of those delegate methods, let's just implement method missing and pass things along to the `SolrDocument`. The benefit is that as we incorporate dynamic metadata, we don't need to keep on adding `delegate :this_property, to: :solr_document`. --- app/presenters/hyrax/work_show_presenter.rb | 26 +++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/presenters/hyrax/work_show_presenter.rb b/app/presenters/hyrax/work_show_presenter.rb index 957d3b5bfd..e16831722c 100644 --- a/app/presenters/hyrax/work_show_presenter.rb +++ b/app/presenters/hyrax/work_show_presenter.rb @@ -16,13 +16,6 @@ class WorkShowPresenter self.collection_presenter_class = CollectionPresenter self.presenter_factory_class = MemberPresenterFactory - # Methods used by blacklight helpers - delegate :has?, :first, :fetch, :export_formats, :export_as, to: :solr_document - - # delegate fields from Hyrax::Works::Metadata to solr_document - delegate :based_near_label, :related_url, :depositor, :identifier, :resource_type, - :keyword, :itemtype, :admin_set, :rights_notes, :access_right, :abstract, to: :solr_document - # @param [SolrDocument] solr_document # @param [Ability] current_ability # @param [ActionDispatch::Request] request the http request context. Used so @@ -37,16 +30,6 @@ def page_title "#{human_readable_type} | #{title.first} | ID: #{id} | #{I18n.t('hyrax.product_name')}" end - # CurationConcern methods - delegate :stringify_keys, :human_readable_type, :collection?, :to_s, :suppressed?, - to: :solr_document - - # Metadata Methods - delegate :title, :date_created, :description, - :creator, :contributor, :subject, :publisher, :language, :embargo_release_date, - :lease_expiration_date, :license, :source, :rights_statement, :thumbnail_id, :representative_id, - :rendering_ids, :member_of_collection_ids, :alternative_title, :bibliographic_citation, to: :solr_document - def workflow @workflow ||= WorkflowPresenter.new(solr_document, current_ability) end @@ -259,6 +242,15 @@ def valkyrie_presenter? private + def method_missing(method_name, *args, &block) + return solr_document.public_send(method_name, *args, &block) if solr_document.respond_to?(method_name) + super + end + + def respond_to_missing?(method_name, include_private = false) + solr_document.respond_to?(method_name, include_private) || super + end + # list of item ids to display is based on ordered_ids def authorized_item_ids(filter_unreadable: Flipflop.hide_private_items?) @member_item_list_ids ||=