Skip to content

Commit

Permalink
♻️ Favor explicit method over class attribute
Browse files Browse the repository at this point in the history
The `class_attribute` best serves cases where we might adjust
configuration at run-time or during initialization.  In the case of of
the class method I am removing, it's subtly different than the ideal use
case for `class_attribute`.

The difference is such:

We include the configuration module into a model; this is the run time
configuration.  And because we've "configured IIIF Print" for that
model, we always will have a `.iiif_print_config?` of true.
  • Loading branch information
jeremyf committed Jan 17, 2024
1 parent cc105d0 commit f0d50f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/indexers/concerns/iiif_print/child_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def self.decorate_work_types!
#

Hyrax.config.curation_concerns.each do |work_type|
next unless work_type.respond_to?(:iiif_print_config)
next unless work_type.respond_to?(:iiif_print_config?)
next unless work_type.iiif_print_config?

work_type.send(:include, IiifPrint::SetChildFlag) unless work_type.included_modules.include?(IiifPrint::SetChildFlag)
indexer = work_type.indexer
Expand Down
6 changes: 4 additions & 2 deletions lib/iiif_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def self.model_configuration(**kwargs)
Module.new do
extend ActiveSupport::Concern

included do
class_attribute :iiif_print_config, default: true
class_method do
def iiif_print_config?; true; end
end

# We don't know what you may want in your configuration, but from this gems implementation,
Expand All @@ -144,6 +144,8 @@ def self.model_configuration(**kwargs)
define_method(:iiif_print_config) do
@iiif_print_config ||= ModelConfig.new(**kwargs)
end

def iiif_print_config?; true; end
end
end

Expand Down

0 comments on commit f0d50f2

Please sign in to comment.