Class: Hyrax::CollectionType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hyrax::CollectionType
- Defined in:
- app/models/hyrax/collection_type.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- SETTINGS_ATTRIBUTES =
these need to updated in tandem with database migrations, use ‘.settings_attributes`
[:nestable?, :discoverable?, :brandable?, :sharable?, :share_applies_to_new_works?, :allow_multiple_membership?, :require_membership?, :assigns_workflow?, :assigns_visibility?].freeze
- USER_COLLECTION_MACHINE_ID =
'user_collection'
- USER_COLLECTION_DEFAULT_TITLE =
I18n.t('hyrax.collection_type.default_title', default: 'User Collection').freeze
- ADMIN_SET_MACHINE_ID =
'admin_set'
- ADMIN_SET_DEFAULT_TITLE =
I18n.t('hyrax.collection_type.admin_set_title', default: 'Admin Set').freeze
Class Method Summary collapse
-
.any_nestable? ⇒ Boolean
True if there is at least one collection type that has nestable? true.
-
.find_by_gid(gid) ⇒ Hyrax::CollectionType, False
Find the collection type associated with the Global Identifier (gid).
-
.find_by_gid!(gid) ⇒ Hyrax::CollectionType
Find the collection type associated with the Global Identifier (gid).
-
.find_or_create_admin_set_type ⇒ Hyrax::CollectionType
Find or create the Admin Set collection type as defined by:.
-
.find_or_create_default_collection_type ⇒ Hyrax::CollectionType
Find or create the default type (i.e., user collection) as defined by:.
-
.for(collection:) ⇒ Hyrax::PcdmCollection | ::Collection
Find the collection type associated with the collection.
-
.gids_that_do_not_allow_multiple_membership ⇒ Array<String>
Return an array of global identifiers for collection types that do not allow multiple membership.
-
.settings_attributes ⇒ Array<Symbol>
The predicates for collection type settings flags (e.g. #nestable?).
Instance Method Summary collapse
-
#admin_set? ⇒ Boolean
True if this is the Admin Set type.
- #collections(use_valkyrie: Hyrax.config.use_valkyrie?, model: Hyrax.config.collection_class) ⇒ Enumerable<Collection, PcdmCollection>
-
#collections? ⇒ Boolean
Query solr to see if any collections of this type exist This should be much more performant for certain adapters than calling collections.any?.
- #title=(value) ⇒ void
-
#user_collection? ⇒ Boolean
True if this is the User Collection type.
Class Method Details
.any_nestable? ⇒ Boolean
Returns True if there is at least one collection type that has nestable? true.
128 129 130 |
# File 'app/models/hyrax/collection_type.rb', line 128 def self.any_nestable? where(nestable: true).any? end |
.find_by_gid(gid) ⇒ Hyrax::CollectionType, False
Find the collection type associated with the Global Identifier (gid)
62 63 64 65 66 |
# File 'app/models/hyrax/collection_type.rb', line 62 def self.find_by_gid(gid) find_by_gid!(gid) rescue ActiveRecord::RecordNotFound, URI::InvalidURIError false end |
.find_by_gid!(gid) ⇒ Hyrax::CollectionType
Find the collection type associated with the Global Identifier (gid)
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/hyrax/collection_type.rb', line 80 def self.find_by_gid!(gid) raise(URI::InvalidURIError) if gid.nil? GlobalID::Locator.locate(gid) rescue NameError Hyrax.logger.warn "#{self.class}##{__method__} called with #{gid}, which is " \ "a legacy collection type global id format. If this " \ "collection type gid is attached to a collection in " \ "your repository you'll want to run " \ "`hyrax:collections:update_collection_type_global_ids` to " \ "update references. see: https://github.com/samvera/hyrax/issues/4696" find(GlobalID.new(gid).model_id) end |
.find_or_create_admin_set_type ⇒ Hyrax::CollectionType
Find or create the Admin Set collection type as defined by:
-
ADMIN_SET_MACHINE_ID
-
ADMIN_SET_DEFAULT_TITLE
-
Hyrax::CollectionTypes::CreateService::ADMIN_SET_OPTIONS
154 155 156 |
# File 'app/models/hyrax/collection_type.rb', line 154 def self.find_or_create_admin_set_type find_by(machine_id: ADMIN_SET_MACHINE_ID) || Hyrax::CollectionTypes::CreateService.create_admin_set_type end |
.find_or_create_default_collection_type ⇒ Hyrax::CollectionType
Find or create the default type (i.e., user collection) as defined by:
-
USER_COLLECTION_MACHINE_ID
-
USER_COLLECTION_DEFAULT_TITLE
-
Hyrax::CollectionTypes::CreateService::USER_COLLECTION_OPTIONS
141 142 143 |
# File 'app/models/hyrax/collection_type.rb', line 141 def self.find_or_create_default_collection_type find_by(machine_id: USER_COLLECTION_MACHINE_ID) || Hyrax::CollectionTypes::CreateService.create_user_collection_type end |
.for(collection:) ⇒ Hyrax::PcdmCollection | ::Collection
Find the collection type associated with the collection
51 52 53 54 55 56 |
# File 'app/models/hyrax/collection_type.rb', line 51 def self.for(collection:) gid = collection.collection_type_gid gid = gid.first if gid.is_a?(Enumerable) find_by_gid!(gid) end |
.gids_that_do_not_allow_multiple_membership ⇒ Array<String>
Return an array of global identifiers for collection types that do not allow multiple membership.
72 73 74 |
# File 'app/models/hyrax/collection_type.rb', line 72 def self.gids_that_do_not_allow_multiple_membership where(allow_multiple_membership: false).map { |c| c.to_global_id.to_s } end |
.settings_attributes ⇒ Array<Symbol>
this replaces the deprecated .collection_type_settings_methods
Returns the predicates for collection type settings flags (e.g. #nestable?).
97 98 99 |
# File 'app/models/hyrax/collection_type.rb', line 97 def self.settings_attributes SETTINGS_ATTRIBUTES end |
Instance Method Details
#admin_set? ⇒ Boolean
Returns True if this is the Admin Set type.
118 119 120 |
# File 'app/models/hyrax/collection_type.rb', line 118 def admin_set? machine_id == ADMIN_SET_MACHINE_ID end |
#collections(use_valkyrie: Hyrax.config.use_valkyrie?, model: Hyrax.config.collection_class) ⇒ Enumerable<Collection, PcdmCollection>
103 104 105 106 107 |
# File 'app/models/hyrax/collection_type.rb', line 103 def collections(use_valkyrie: Hyrax.config.use_valkyrie?, model: Hyrax.config.collection_class) return [] unless id return Hyrax.custom_queries.find_collections_by_type(global_id: to_global_id.to_s, model:) if use_valkyrie ActiveFedora::Base.where(Hyrax.config.collection_type_index_field.to_sym => to_global_id.to_s) end |
#collections? ⇒ Boolean
Query solr to see if any collections of this type exist This should be much more performant for certain adapters than calling collections.any?
112 113 114 115 |
# File 'app/models/hyrax/collection_type.rb', line 112 def collections? return false unless id Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: { Hyrax.config.collection_type_index_field.to_sym => to_global_id.to_s }).with_model(model: Hyrax.config.collection_class.to_rdf_representation).count > 0 end |
#title=(value) ⇒ void
mints a #machine_id (?!)
This method returns an undefined value.
34 35 36 37 |
# File 'app/models/hyrax/collection_type.rb', line 34 def title=(value) super assign_machine_id end |
#user_collection? ⇒ Boolean
Returns True if this is the User Collection type.
123 124 125 |
# File 'app/models/hyrax/collection_type.rb', line 123 def user_collection? machine_id == USER_COLLECTION_MACHINE_ID end |