-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Extracting naming container (#6694)
* ♻️ Extracting naming container Throughout the code we have quite a bit of conditionals regarding what is a work, collection, file_set, and adminsitrative set. This model attempts to provide a common point to interrogate the application. There are, at present, no refactors to use this model. Consider how our specs and our application are inconsistent in their declaration/configuration/stubbing. This model should help with that. * ♻️ Favor Hyrax::ModelRegistry for search builders Instead of the myriad of ways of asking about which models to use, let's leverage a consolidated central place for information. This is but one step in addressing other issues. * ♻️ Leverage Hyrax::ModelRegistry for ability tests * 💄 endless and ever appeasing of the coppers * ♻️ Favor Hyrax::ModelRegistry For those reading along, I removed an assertion from `spec/features/dashboard/collection_spec.rb`. Why? Because the test was creating one type of admin set, and the queries for what to show was filtering on other kinds of admin sets. Ultimatley creating a false assertion. * ♻️ Fixing spec * Adding case statement * ☑️ Fix stubbing * ♻️ Favor helper method * ♻️ Favor dynamic value * Favor helper method over instance variable * 🐛 Favor helper method over instance variable Prior to this commit, if the `update` failed, we would not have set the `@collection_type` instance variable. Which would mean that we'd raise a `NoMethodError` on `NilClass` in the `app/views/hyrax/dashboard/collections/_form_share_table.html.erb` view. By favoring a helper method, we no longer require that the edit (nor create) call the collection_type method. Below is the the only view references for `@collection_type`, so the helper_method appears to be adequate. ```shell ❯ rg "@collection_type[\. ]" app/views app/views/hyrax/dashboard/collections/_form_share_table.html.erb 5: <p><%= t(".#{access}.help_with_works", type_title: @collection_type.title) if @collection_type.share_applies_to_new_works? && access != 'depositors' %></p> app/views/hyrax/admin/collection_types/_form.html.erb 22: <% if @collection_type.admin_set? %> ``` * Adding Hyrax.config.file_set_model * Update app/models/hyrax/model_registry.rb * 🧹 An empty commit --------- Co-authored-by: Daniel Pierce <dlpierce@indiana.edu>
- Loading branch information
Showing
28 changed files
with
228 additions
and
102 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
## | ||
# There are four conceptual high-level models for the metadata modeling: | ||
# | ||
# - AdminSet :: Where things are "physically" stored. | ||
# - Collection :: What things "logically" belong to. | ||
# - Work :: What the thing is about; these are often sub-divided into different work types | ||
# (e.g. an Article, a Monograph, etc.) | ||
# - FileSet :: Artifacts that further describe the thing. | ||
# | ||
# The purpose of this module is to provide an overview and map of the modeling concepts. This is | ||
# envisioned as a module to interrogate to see how Hyrax conceptually organizes your models. | ||
# | ||
# For each of the above high-level models the {Hyrax::ModelRegistry} implements two methods: | ||
# | ||
# - <model_type>_classes :: These are the Ruby constants that represent the conceptual models. | ||
# - <model_type>_rdf_representations :: These are the stored strings that help us describe what # | ||
# - the data models. Very useful in our Solr queries when we want to filter/query on the | ||
# - "has_model_ssim" attribute. | ||
# | ||
# Consider that an {AdminSet} and a {Hyrax::AdministrativeSet} conceptually model the same thing; | ||
# the latter implements via Valkyrie and the former via ActiveFedora. | ||
# | ||
# @note Due to the shift from ActiveFedora to Valkyrie, we are at a crossroads where we might have | ||
# multiple models for the versions: an ActiveFedora AdminSet and a Valkyrie AdminSet. | ||
class ModelRegistry | ||
## | ||
# @return [Array<String>] | ||
def self.admin_set_class_names | ||
["::AdminSet", "::Hyrax::AdministrativeSet", Hyrax.config.admin_set_model].uniq | ||
end | ||
|
||
## | ||
# @return [Array<Class>] | ||
def self.admin_set_classes | ||
classes_from(admin_set_class_names) | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.admin_set_rdf_representations | ||
rdf_representations_from(admin_set_classes) | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.collection_class_names | ||
["::Collection", "::Hyrax::PcdmCollection", Hyrax.config.collection_model].uniq | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.collection_classes | ||
classes_from(collection_class_names) | ||
end | ||
|
||
def self.collection_rdf_representations | ||
rdf_representations_from(collection_classes) | ||
end | ||
|
||
def self.collection_has_model_ssim | ||
collection_rdf_representations | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.file_set_class_names | ||
["::FileSet", "::Hyrax::FileSet", Hyrax.config.file_set_model].uniq | ||
end | ||
|
||
def self.file_set_classes | ||
classes_from(file_set_class_names) | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.file_set_rdf_representations | ||
rdf_representations_from(file_set_classes) | ||
end | ||
|
||
## | ||
# @return [Array<Class>] | ||
# | ||
# @todo Consider the Wings::ModelRegistry and how we perform mappings. | ||
def self.work_class_names | ||
Hyrax.config.registered_curation_concern_types | ||
end | ||
|
||
def self.work_classes | ||
classes_from(work_class_names) | ||
end | ||
|
||
## | ||
# @return [Array<String>] | ||
def self.work_rdf_representations | ||
rdf_representations_from(work_classes) | ||
end | ||
|
||
def self.classes_from(strings) | ||
strings.map(&:safe_constantize).flatten.uniq | ||
end | ||
private_class_method :classes_from | ||
|
||
def self.rdf_representations_from(klasses) | ||
klasses.map { |klass| klass.respond_to?(:to_rdf_represntation) ? klass.to_rdf_represntation : klass.name }.uniq | ||
end | ||
private_class_method :rdf_representations_from | ||
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
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
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
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
Oops, something went wrong.