-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Simpson
committed
Feb 19, 2024
1 parent
364be47
commit 27a1aab
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module NoteFormBehavior | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
self.terms += [:note] | ||
|
||
delegate :note, to: :model | ||
end | ||
|
||
class_methods do | ||
def build_permitted_params | ||
super.tap { |permitted_params| permitted_params << [:note] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/presenters/concerns/hyku_knapsack/presenter_delegatable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module PresenterDelegatable | ||
extend ActiveSupport::Concern | ||
|
||
def self.delegated_methods | ||
raise NotImplementedError, "delegated_methods must return an array of method names" | ||
end | ||
|
||
included do | ||
# Check if any other concerns have registered methods before delegating, which prevents | ||
# concerns like Hyrax::DOI::DOIPresenterBehavior trying to register a helper `doi` method | ||
# which is not called, as we already delegated the method and it could not be overwritten. | ||
delegated_methods.each { |method| delegate(method, to: :solr_document) unless instance_methods.include?(method) } | ||
|
||
# NOTE: | ||
# I hate this being here, and wonder if it wouldn't be better to just include it on every | ||
# presenter than needs to delegate isbn? | ||
alias_method :isbns, :isbn if respond_to?(:delegated_methods) && delegated_methods.include?(:isbn) | ||
end | ||
end | ||
end |