Module: Cocina::Models
- Defined in:
- lib/cocina/models.rb,
lib/cocina/models/doi.rb,
lib/cocina/models/dro.rb,
lib/cocina/models/file.rb,
lib/cocina/models/purl.rb,
lib/cocina/models/druid.rb,
lib/cocina/models/event.rb,
lib/cocina/models/title.rb,
lib/cocina/models/utils.rb,
lib/cocina/models/access.rb,
lib/cocina/models/source.rb,
lib/cocina/models/barcode.rb,
lib/cocina/models/embargo.rb,
lib/cocina/models/license.rb,
lib/cocina/models/version.rb,
lib/cocina/models/dro_lite.rb,
lib/cocina/models/file_set.rb,
lib/cocina/models/file_use.rb,
lib/cocina/models/language.rb,
lib/cocina/models/sequence.rb,
lib/cocina/models/standard.rb,
lib/cocina/models/checkable.rb,
lib/cocina/models/copyright.rb,
lib/cocina/models/source_id.rb,
lib/cocina/models/applies_to.rb,
lib/cocina/models/collection.rb,
lib/cocina/models/dro_access.rb,
lib/cocina/models/geographic.rb,
lib/cocina/models/vocabulary.rb,
lib/cocina/models/access_role.rb,
lib/cocina/models/contributor.rb,
lib/cocina/models/dark_access.rb,
lib/cocina/models/description.rb,
lib/cocina/models/file_access.rb,
lib/cocina/models/object_type.rb,
lib/cocina/models/request_dro.rb,
lib/cocina/models/validatable.rb,
lib/cocina/models/admin_policy.rb,
lib/cocina/models/catalog_link.rb,
lib/cocina/models/language_tag.rb,
lib/cocina/models/mapping/purl.rb,
lib/cocina/models/presentation.rb,
lib/cocina/models/request_file.rb,
lib/cocina/models/world_access.rb,
lib/cocina/models/file_set_type.rb,
lib/cocina/models/libraries_doi.rb,
lib/cocina/models/administrative.rb,
lib/cocina/models/catkey_barcode.rb,
lib/cocina/models/cocina_version.rb,
lib/cocina/models/doi_exceptions.rb,
lib/cocina/models/dro_structural.rb,
lib/cocina/models/identification.rb,
lib/cocina/models/message_digest.rb,
lib/cocina/models/repository_doi.rb,
lib/cocina/models/collection_lite.rb,
lib/cocina/models/object_metadata.rb,
lib/cocina/models/stanford_access.rb,
lib/cocina/models/business_barcode.rb,
lib/cocina/models/related_resource.rb,
lib/cocina/models/request_file_set.rb,
lib/cocina/models/standard_barcode.rb,
lib/cocina/models/admin_policy_lite.rb,
lib/cocina/models/collection_access.rb,
lib/cocina/models/descriptive_value.rb,
lib/cocina/models/dro_with_metadata.rb,
lib/cocina/models/access_role_member.rb,
lib/cocina/models/folio_catalog_link.rb,
lib/cocina/models/request_collection.rb,
lib/cocina/models/file_administrative.rb,
lib/cocina/models/file_set_structural.rb,
lib/cocina/models/mapping/escape_html.rb,
lib/cocina/models/request_description.rb,
lib/cocina/models/citation_only_access.rb,
lib/cocina/models/lane_medical_barcode.rb,
lib/cocina/models/mapping/to_mods/form.rb,
lib/cocina/models/mapping/to_mods/note.rb,
lib/cocina/models/request_admin_policy.rb,
lib/cocina/models/validators/validator.rb,
lib/cocina/models/location_based_access.rb,
lib/cocina/models/mapping/to_mods/event.rb,
lib/cocina/models/mapping/to_mods/title.rb,
lib/cocina/models/symphony_catalog_link.rb,
lib/cocina/models/builders/title_builder.rb,
lib/cocina/models/mapping/error_notifier.rb,
lib/cocina/models/mapping/from_mods/form.rb,
lib/cocina/models/mapping/from_mods/note.rb,
lib/cocina/models/mapping/from_mods/purl.rb,
lib/cocina/models/mapping/to_mods/access.rb,
lib/cocina/models/request_administrative.rb,
lib/cocina/models/request_dro_structural.rb,
lib/cocina/models/request_identification.rb,
lib/cocina/models/descriptive_basic_value.rb,
lib/cocina/models/mapping/from_mods/event.rb,
lib/cocina/models/mapping/from_mods/title.rb,
lib/cocina/models/mapping/to_mods/subject.rb,
lib/cocina/models/collection_with_metadata.rb,
lib/cocina/models/mapping/from_mods/access.rb,
lib/cocina/models/mapping/normalizers/base.rb,
lib/cocina/models/mapping/to_mods/language.rb,
lib/cocina/models/collection_identification.rb,
lib/cocina/models/descriptive_grouped_value.rb,
lib/cocina/models/mapping/from_mods/primary.rb,
lib/cocina/models/mapping/from_mods/subject.rb,
lib/cocina/models/validators/dark_validator.rb,
lib/cocina/models/validators/purl_validator.rb,
lib/cocina/models/admin_policy_with_metadata.rb,
lib/cocina/models/descriptive_admin_metadata.rb,
lib/cocina/models/descriptive_parallel_event.rb,
lib/cocina/models/descriptive_parallel_value.rb,
lib/cocina/models/descriptive_value_language.rb,
lib/cocina/models/mapping/from_mods/language.rb,
lib/cocina/models/mapping/to_mods/geographic.rb,
lib/cocina/models/mapping/to_mods/identifier.rb,
lib/cocina/models/admin_policy_administrative.rb,
lib/cocina/models/created_in_folio_identifier.rb,
lib/cocina/models/descriptive_access_metadata.rb,
lib/cocina/models/mapping/from_mods/authority.rb,
lib/cocina/models/mapping/from_mods/value_uri.rb,
lib/cocina/models/mapping/to_mods/contributor.rb,
lib/cocina/models/mapping/to_mods/description.rb,
lib/cocina/models/mapping/to_mods/mods_writer.rb,
lib/cocina/models/mapping/to_mods/name_writer.rb,
lib/cocina/models/mapping/to_mods/part_writer.rb,
lib/cocina/models/mapping/to_mods/role_writer.rb,
lib/cocina/models/request_file_set_structural.rb,
lib/cocina/models/validators/w3cdtf_validator.rb,
lib/cocina/models/admin_policy_access_template.rb,
lib/cocina/models/descriptive_structured_value.rb,
lib/cocina/models/mapping/from_mods/geographic.rb,
lib/cocina/models/mapping/from_mods/identifier.rb,
lib/cocina/models/mapping/to_mods/id_generator.rb,
lib/cocina/models/preregistered_repository_doi.rb,
lib/cocina/models/mapping/from_mods/contributor.rb,
lib/cocina/models/mapping/from_mods/description.rb,
lib/cocina/models/validators/open_api_validator.rb,
lib/cocina/models/location_based_download_access.rb,
lib/cocina/models/mapping/from_mods/name_builder.rb,
lib/cocina/models/mapping/from_mods/part_builder.rb,
lib/cocina/models/mapping/to_mods/admin_metadata.rb,
lib/cocina/models/use_and_reproduction_statement.rb,
lib/cocina/models/validators/date_time_validator.rb,
lib/cocina/models/descriptive_geographic_metadata.rb,
lib/cocina/models/mapping/from_mods/alt_rep_group.rb,
lib/cocina/models/mapping/from_mods/language_term.rb,
lib/cocina/models/mapping/from_mods/title_builder.rb,
lib/cocina/models/descriptive_parallel_contributor.rb,
lib/cocina/models/mapping/from_mods/admin_metadata.rb,
lib/cocina/models/mapping/to_mods/name_title_group.rb,
lib/cocina/models/mapping/to_mods/related_resource.rb,
lib/cocina/models/migrated_from_voyager_identifier.rb,
lib/cocina/models/builders/name_title_group_builder.rb,
lib/cocina/models/controlled_digital_lending_access.rb,
lib/cocina/models/mapping/from_mods/identifier_type.rb,
lib/cocina/models/mapping/from_mods/language_script.rb,
lib/cocina/models/migrated_from_symphony_identifier.rb,
lib/cocina/models/validators/language_tag_validator.rb,
lib/cocina/models/mapping/from_mods/related_resource.rb,
lib/cocina/models/validators/catalog_links_validator.rb,
lib/cocina/models/builders/rights_description_builder.rb,
lib/cocina/models/mapping/normalizers/mods_normalizer.rb,
lib/cocina/models/mapping/from_mods/identifier_builder.rb,
lib/cocina/models/validators/associated_name_validator.rb,
lib/cocina/models/mapping/from_mods/description_builder.rb,
lib/cocina/models/validators/description_types_validator.rb,
lib/cocina/models/validators/reserved_filename_validator.rb,
lib/cocina/models/builders/dro_rights_description_builder.rb,
lib/cocina/models/validators/description_values_validator.rb,
lib/cocina/models/mapping/from_mods/title_builder_strategy.rb,
lib/cocina/models/mapping/normalizers/mods/name_normalizer.rb,
lib/cocina/models/mapping/from_mods/subject_authority_codes.rb,
lib/cocina/models/mapping/normalizers/mods/title_normalizer.rb,
lib/cocina/models/mapping/normalizers/mods/subject_normalizer.rb,
lib/cocina/models/mapping/from_mods/hydrus_default_title_builder.rb,
lib/cocina/models/mapping/normalizers/mods/origin_info_normalizer.rb,
lib/cocina/models/mapping/normalizers/mods/geo_extension_normalizer.rb
Overview
Provides Ruby objects for the repository and serializing them to/from JSON.
Defined Under Namespace
Modules: Builders, Checkable, Mapping, Types, Utils, Validatable, Validators Classes: Access, AccessRole, AccessRoleMember, AdminPolicy, AdminPolicyAccessTemplate, AdminPolicyAdministrative, AdminPolicyLite, AdminPolicyWithMetadata, Administrative, AppliesTo, CitationOnlyAccess, Collection, CollectionAccess, CollectionIdentification, CollectionLite, CollectionWithMetadata, Contributor, ControlledDigitalLendingAccess, DRO, DROAccess, DROLite, DROStructural, DROWithMetadata, DarkAccess, Description, DescriptiveAccessMetadata, DescriptiveAdminMetadata, DescriptiveBasicValue, DescriptiveGeographicMetadata, DescriptiveGroupedValue, DescriptiveParallelContributor, DescriptiveParallelEvent, DescriptiveParallelValue, DescriptiveStructuredValue, DescriptiveValue, DescriptiveValueLanguage, Embargo, Error, Event, File, FileAccess, FileAdministrative, FileSet, FileSetStructural, FileSetType, FolioCatalogLink, Geographic, Identification, Language, LocationBasedAccess, LocationBasedDownloadAccess, MessageDigest, ObjectMetadata, ObjectType, Presentation, RelatedResource, RequestAdminPolicy, RequestAdministrative, RequestCollection, RequestDRO, RequestDROStructural, RequestDescription, RequestFile, RequestFileSet, RequestFileSetStructural, RequestIdentification, Sequence, Source, Standard, StanfordAccess, Struct, SymphonyCatalogLink, Title, UnknownTypeError, ValidationError, Vocabulary, WorldAccess
Constant Summary collapse
- METADATA_KEYS =
rubocop:enable Naming/MethodName
i[created modified lock].freeze
- DOI =
Digital Object Identifier (www.doi.org)
RepositoryDOI | PreregisteredRepositoryDOI | LibrariesDOI | DOIExceptions
- Purl =
Stanford persistent URL associated with the related resource.
Types::String.constrained(format: %r{^https://})
- Druid =
example: druid:bc123df4567
Types::String.constrained(format: /^druid:[b-df-hjkmnp-tv-z]{2}[0-9]{3}[b-df-hjkmnp-tv-z]{2}[0-9]{4}$/)
- Barcode =
A barcode
BusinessBarcode | LaneMedicalBarcode | CatkeyBarcode | StandardBarcode
- License =
The license governing reuse of the DRO. Should be an IRI for known licenses (i.e. CC, RightsStatement.org URI, etc.).
Types::String.enum('https://www.gnu.org/licenses/agpl.txt', 'https://www.apache.org/licenses/LICENSE-2.0', 'https://opensource.org/licenses/BSD-2-Clause', 'https://opensource.org/licenses/BSD-3-Clause', 'https://creativecommons.org/licenses/by/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode', 'https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode', 'https://creativecommons.org/licenses/by-nd/4.0/legalcode', 'https://creativecommons.org/licenses/by-sa/4.0/legalcode', 'https://creativecommons.org/publicdomain/zero/1.0/legalcode', 'https://opensource.org/licenses/cddl1', 'https://www.eclipse.org/legal/epl-2.0', 'https://www.gnu.org/licenses/gpl-3.0-standalone.html', 'https://www.isc.org/downloads/software-support-policy/isc-license/', 'https://www.gnu.org/licenses/lgpl-3.0-standalone.html', 'https://opensource.org/licenses/MIT', 'https://www.mozilla.org/MPL/2.0/', 'https://opendatacommons.org/licenses/by/1-0/', 'http://opendatacommons.org/licenses/odbl/1.0/', 'https://opendatacommons.org/licenses/odbl/1-0/', 'https://creativecommons.org/publicdomain/mark/1.0/', 'https://opendatacommons.org/licenses/pddl/1-0/', 'https://creativecommons.org/licenses/by/3.0/legalcode', 'https://creativecommons.org/licenses/by-sa/3.0/legalcode', 'https://creativecommons.org/licenses/by-nd/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', 'https://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', 'https://cocina.sul.stanford.edu/licenses/none')
- VERSION =
'0.108.3'- FileUse =
Use for the File (e.g. “transcription” for OCR).
Types::String
- Copyright =
The human readable copyright statement that applies example: Copyright World Trade Organization
Types::String
- SourceId =
example: sul:PC0170_s3_Fiesta_Bowl_2012-01-02_210609_2026
Types::String.constrained(format: /^.+:.+$/)
- CatalogLink =
A linkage between an object and a catalog record
FolioCatalogLink | SymphonyCatalogLink
- LanguageTag =
BCP 47 language tag: www.rfc-editor.org/rfc/rfc4646.txt – other applications (like media players) expect language codes of this format, see e.g. videojs.com/guides/text-tracks/#srclang
Types::String
- LibrariesDOI =
The DOI (Digital Object Identifier, www.doi.org) pattern for works registered by Stanford Libraries outside of SDR workflows. Please note that DOIs are not case-sensitive so both cases of letters should be permitted. example: 10.25936/629T-bx79
Types::String.constrained(format: %r{^10\.25936/[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}$})
- CatkeyBarcode =
The barcode associated with a DRO object based on catkey, prefixed with a catkey followed by a hyphen example: 6772719-1001
Types::String.constrained(format: /^[0-9]+-[0-9]+$/)
- CocinaVersion =
The version of Cocina with which this object conforms. example: 1.2.3
Types::String.constrained(format: /^\d+\.\d+\.\d+$/)
- DOIExceptions =
The DOI (Digital Object Identifier, www.doi.org) pattern for objects in SDR that do not adhere to any of the other DOI patterns in the spec. This is a short list of known exceptions only. Please note that DOIs are not case-sensitive, so we allow for uppercase and lowercase letters with these exceptions. example: 10.18735/0mw1-qq72
Types::String.constrained(format: %r{^10\.25936/[jJ][mM]709[hH][cC]8700|10\.18735/4[nN][sS][eE]-8871|10\.18735/952[xX]-[wW]447|10\.18735/0[mM][wW]1-[qQ][qQ]72$})
- RepositoryDOI =
The DOI (Digital Object Identifier, www.doi.org) pattern for SDR objects, based on the object’s repository identifier. Permits both production and text prefixes to be used to account for objects in different SDR environments. Please note that while DOIs are not case-sensitive, we constrain the DOIs we mint for SDR to lowercase for consistency. example: 10.25740/bc123df4567
Types::String.constrained(format: %r{^10\.(25740|80343)/[b-df-hjkmnp-tv-z]{2}[0-9]{3}[b-df-hjkmnp-tv-z]{2}[0-9]{4}$})
- BusinessBarcode =
The barcode associated with a business library DRO object, prefixed with 2050 example: 20503740296
Types::String.constrained(format: /^2050[0-9]{7}$/)
- StandardBarcode =
The standard barcode associated with a DRO object, prefixed with 36105 example: 36105010362304
Types::String.constrained(format: /^36105[0-9]{9}$/)
- LaneMedicalBarcode =
The barcode associated with a Lane Medical Library DRO object, prefixed with 245 example: 24503259768
Types::String.constrained(format: /^245[0-9]{8}$/)
- CreatedInFolioIdentifier =
A record identifier created in Folio example: in11403803
Types::String.constrained(format: /^in\d+$/)
- PreregisteredRepositoryDOI =
The DOI (Digital Object Identifier, www.doi.org) pattern for DOIs registered before an SDR object has been registered—i.e., before it has a druid, which is a common pattern as of 2025. Please note that DOIs are not case-sensitive so both cases of letters should be permitted. example: 10.80343/12qF-5243
Types::String.constrained(format: %r{^10\.(25740|80343)/[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}$})
- UseAndReproductionStatement =
The human readable use and reproduction statement that applies example: Property rights reside with the repository. Literary rights reside with the creators of the documents or their heirs. To obtain permission to publish or reproduce, please contact the Public Services Librarian of the Dept. of Special Collections (library.stanford.edu/spc).
Types::String
- MigratedFromVoyagerIdentifier =
A record identifier migrated from Voyager example: L11403803
Types::String.constrained(format: /^L\d+$/)
- MigratedFromSymphonyIdentifier =
A record identifier migrated from Symphony example: a11403803
Types::String.constrained(format: /^a\d+$/)
Class Method Summary collapse
- .build(dyn, validate: true) ⇒ DRO, ...
-
.build_lite(dyn) ⇒ DROLite, ...
Build “lite” versions of DROs, Collections, and AdminPolicies.
- .build_request(dyn, validate: true) ⇒ RequestDRO, ...
- .druid_regex ⇒ Object
-
.Vocabulary(uri) ⇒ Class
Alias for ‘Cocina::Models::Vocabulary.create`.
-
.with_metadata(cocina_object, lock, created: nil, modified: nil) ⇒ DROWithMetadata, ...
Adds metadata to a DRO, Collection, AdminPolicy or updates for a DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata.
-
.without_metadata(cocina_object) ⇒ DRO, ...
Coerces DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata to DRO, Collection, AdminPolicy.
Class Method Details
.build(dyn, validate: true) ⇒ DRO, ...
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/cocina/models.rb', line 97 def self.build(dyn, validate: true) clazz = case type_for(dyn) when *DRO::TYPES (dyn) ? DROWithMetadata : DRO when *Collection::TYPES (dyn) ? CollectionWithMetadata : Collection when *AdminPolicy::TYPES (dyn) ? AdminPolicyWithMetadata : AdminPolicy else raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'" end clazz.new(dyn, false, validate) end |
.build_lite(dyn) ⇒ DROLite, ...
Build “lite” versions of DROs, Collections, and AdminPolicies. Lite versions do not require attributes that are required in the normal versions. For example, “description” is required for a DRO, but optional for a DROLite. Lite versions also are not validated / validatable. Lite versions are useful for instantiating partially populated cocina objects similar to an ActiveRecord instantiated using .select (See guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cocina/models.rb', line 141 def self.build_lite(dyn) clazz = case type_for(dyn) when *DRO::TYPES DROLite when *Collection::TYPES CollectionLite when *AdminPolicy::TYPES AdminPolicyLite else raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'" end # dyn for lite may contain extra keys clazz.new(dyn.with_indifferent_access.slice(*clazz.attribute_names)) end |
.build_request(dyn, validate: true) ⇒ RequestDRO, ...
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cocina/models.rb', line 117 def self.build_request(dyn, validate: true) clazz = case type_for(dyn) when *DRO::TYPES RequestDRO when *Collection::TYPES RequestCollection when *AdminPolicy::TYPES RequestAdminPolicy else raise UnknownTypeError, "Unknown type: '#{dyn.with_indifferent_access.fetch('type')}'" end clazz.new(dyn, false, validate) end |
.druid_regex ⇒ Object
206 207 208 209 210 211 212 213 214 |
# File 'lib/cocina/models.rb', line 206 def self.druid_regex @druid_regex ||= begin str = OpenAPIParser.parse(YAML.load_file('openapi.yml'), strict_reference_validation: true) .find_object('#/components') .schemas['Druid'] .pattern Regexp.new(str) end end |
.Vocabulary(uri) ⇒ Class
Alias for ‘Cocina::Models::Vocabulary.create`.
rubocop:disable Naming/MethodName
84 85 86 |
# File 'lib/cocina/models.rb', line 84 def self.Vocabulary(uri) Vocabulary.create(uri) end |
.with_metadata(cocina_object, lock, created: nil, modified: nil) ⇒ DROWithMetadata, ...
Adds metadata to a DRO, Collection, AdminPolicy or updates for a DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/cocina/models.rb', line 171 def self.(cocina_object, lock, created: nil, modified: nil) props = cocina_object.to_h props[:created] = created.iso8601 if created props[:modified] = modified.iso8601 if modified props[:lock] = lock clazz = case cocina_object.type when *DRO::TYPES DROWithMetadata when *Collection::TYPES CollectionWithMetadata else AdminPolicyWithMetadata end clazz.new(props, false, false) end |
.without_metadata(cocina_object) ⇒ DRO, ...
Coerces DROWithMetadata, CollectionWithMetadata, AdminPolicyWithMetadata to DRO, Collection, AdminPolicy
159 160 161 |
# File 'lib/cocina/models.rb', line 159 def self.(cocina_object) build(cocina_object.to_h.except(*METADATA_KEYS), validate: false) end |