-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a factory for a cocina object
- Loading branch information
Showing
13 changed files
with
77 additions
and
284 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cocina | ||
module Models | ||
class Factories | ||
def self.build(type, attributes = {}) | ||
case type | ||
when :item | ||
build_item(attributes) | ||
end | ||
end | ||
|
||
ITEM_DEFAULTS = { | ||
type: Cocina::Models::ObjectType.object, | ||
id: 'druid:bc234fg5678', | ||
version: 1, | ||
label: 'test object', | ||
title: 'test object', | ||
source_id: 'sul:1234', | ||
admin_policy_id: 'druid:hv992ry2431' | ||
}.freeze | ||
|
||
# rubocop:disable Metrics/ParameterLists | ||
def self.build_item_properties(type:, id:, version:, label:, title:, source_id:, admin_policy_id:, catkeys: []) | ||
{ | ||
type: type, | ||
externalIdentifier: id, | ||
version: version, | ||
label: label, | ||
access: {}, | ||
administrative: { hasAdminPolicy: admin_policy_id }, | ||
description: { | ||
title: [{ value: title }], | ||
purl: "https://purl.stanford.edu/#{id.delete_prefix('druid:')}" | ||
}, | ||
identification: { | ||
sourceId: source_id | ||
}, | ||
structural: {} | ||
}.tap do |props| | ||
props[:identification][:catalogLinks] = catkeys.map { |catkey| { catalog: 'symphony', catalogRecordId: catkey } } if catkeys.present? | ||
end | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
def self.build_item(attributes) | ||
Cocina::Models.build(build_item_properties(**ITEM_DEFAULTS.merge(attributes))) | ||
end | ||
end | ||
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
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.