Class: Hyrax::CollectionType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hyrax::CollectionType
- Defined in:
- app/models/hyrax/collection_type.rb
Constant Summary collapse
- USER_COLLECTION_MACHINE_ID =
'user_collection'.freeze
- USER_COLLECTION_DEFAULT_TITLE =
I18n.t('hyrax.collection_type.default_title').freeze
- ADMIN_SET_MACHINE_ID =
'admin_set'.freeze
- ADMIN_SET_DEFAULT_TITLE =
I18n.t('hyrax.collection_type.admin_set_title').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:.
Instance Method Summary collapse
-
#admin_set? ⇒ Boolean
True if this is the Admin Set type.
- #collections ⇒ Object
-
#collections? ⇒ Boolean
True if there is at least one collection of this type.
-
#gid ⇒ String
Return the Global Identifier for this collection type.
- #title=(value) ⇒ Object
-
#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.
83 84 85 |
# File 'app/models/hyrax/collection_type.rb', line 83 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)
40 41 42 43 44 |
# File 'app/models/hyrax/collection_type.rb', line 40 def self.find_by_gid(gid) find(GlobalID.new(gid).model_id) rescue ActiveRecord::RecordNotFound, URI::InvalidURIError false end |
.find_by_gid!(gid) ⇒ Hyrax::CollectionType
Find the collection type associated with the Global Identifier (gid)
50 51 52 53 54 |
# File 'app/models/hyrax/collection_type.rb', line 50 def self.find_by_gid!(gid) result = find_by_gid(gid) raise ActiveRecord::RecordNotFound, "Couldn't find Hyrax::CollectionType matching GID '#{gid}'" unless result result 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
109 110 111 |
# File 'app/models/hyrax/collection_type.rb', line 109 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
96 97 98 |
# File 'app/models/hyrax/collection_type.rb', line 96 def self.find_or_create_default_collection_type find_by(machine_id: USER_COLLECTION_MACHINE_ID) || Hyrax::CollectionTypes::CreateService.create_user_collection_type end |
Instance Method Details
#admin_set? ⇒ Boolean
Returns True if this is the Admin Set type.
73 74 75 |
# File 'app/models/hyrax/collection_type.rb', line 73 def admin_set? machine_id == ADMIN_SET_MACHINE_ID end |
#collections ⇒ Object
62 63 64 65 |
# File 'app/models/hyrax/collection_type.rb', line 62 def collections return [] unless gid ActiveFedora::Base.where(collection_type_gid_ssim: gid.to_s) end |
#collections? ⇒ Boolean
Returns True if there is at least one collection of this type.
68 69 70 |
# File 'app/models/hyrax/collection_type.rb', line 68 def collections? collections.count.positive? end |
#gid ⇒ String
Return the Global Identifier for this collection type.
58 59 60 |
# File 'app/models/hyrax/collection_type.rb', line 58 def gid URI::GID.build(app: GlobalID.app, model_name: model_name.name.parameterize.to_sym, model_id: id).to_s if id end |
#title=(value) ⇒ Object
18 19 20 21 |
# File 'app/models/hyrax/collection_type.rb', line 18 def title=(value) super assign_machine_id end |
#user_collection? ⇒ Boolean
Returns True if this is the User Collection type.
78 79 80 |
# File 'app/models/hyrax/collection_type.rb', line 78 def user_collection? machine_id == USER_COLLECTION_MACHINE_ID end |