cocina-models 0.87.0 → 0.88.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 272a5d8e2b026dc773452921e549241338c6c8cda4f21b3ae6da3b7511f7cec6
4
- data.tar.gz: f3471e9e52d279444b8ef4bac802d116c71b23d5d937363c084f322204b9ce1f
3
+ metadata.gz: bc554199583e2b12406431ed5078bae08509c75989a7aafdcf22715530f3d5da
4
+ data.tar.gz: f2bd63b4b242d7f48156499fdf729935bccc728635c692628cd1e3ebb0c84cd5
5
5
  SHA512:
6
- metadata.gz: a44093101a258a2d88b83f82955dc81c81624419baf0cf55892eb976e04ac770ddf34d8c60e5649522c1c4b14687aed0715b14b92ede2a8858af839ff2bb6b8e
7
- data.tar.gz: a95e82570f152ac1498d072c0ee7320c0da738a45b80949cb098c722838d9495cd4e6c6e74aa78cf40ba6f3b88ea846779cc2adbddd42d161929ae8bd79a7856
6
+ metadata.gz: afaca98ac0c7260962d483ed4ff4bc0a4c9bf1c3aa538b1571541b98b2ef6d6efd9a00e0575fffd3117adc8dbd75426b4e4dffeb1ebfae4a46fa0db1c1a3e3b1
7
+ data.tar.gz: '090a1137f535c219c96966b44a8af03a9a60bdf9dd871c4b6024a033d4323ffc3f000132835d71d55aa60a80f38b7601663b6403b05e6df69a699395ccdf9f99'
data/.rubocop.yml CHANGED
@@ -392,3 +392,5 @@ RSpec/Rails/InferredSpecType: # new in 2.14
392
392
  Enabled: true
393
393
  RSpec/Rails/MinitestAssertions: # new in 2.17
394
394
  Enabled: true
395
+ Style/RedundantHeredocDelimiterQuotes: # new in 1.45
396
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cocina-models (0.87.0)
4
+ cocina-models (0.88.0)
5
5
  activesupport
6
6
  deprecation
7
7
  dry-struct (~> 1.0)
@@ -51,11 +51,11 @@ GEM
51
51
  dry-types (>= 1.7, < 2)
52
52
  ice_nine (~> 0.11)
53
53
  zeitwerk (~> 2.6)
54
- dry-types (1.7.0)
54
+ dry-types (1.7.1)
55
55
  concurrent-ruby (~> 1.0)
56
- dry-core (~> 1.0, < 2)
57
- dry-inflector (~> 1.0, < 2)
58
- dry-logic (>= 1.4, < 2)
56
+ dry-core (~> 1.0)
57
+ dry-inflector (~> 1.0)
58
+ dry-logic (~> 1.4)
59
59
  zeitwerk (~> 2.6)
60
60
  edtf (3.1.1)
61
61
  activesupport (>= 3.0, < 8.0)
@@ -118,7 +118,7 @@ GEM
118
118
  unicode-display_width (>= 2.4.0, < 3.0)
119
119
  rubocop-ast (1.26.0)
120
120
  parser (>= 3.2.1.0)
121
- rubocop-capybara (2.17.0)
121
+ rubocop-capybara (2.17.1)
122
122
  rubocop (~> 1.41)
123
123
  rubocop-rake (0.6.0)
124
124
  rubocop (~> 1.0)
@@ -24,10 +24,16 @@ module Cocina
24
24
  key || schema_doc.name
25
25
  end
26
26
 
27
- # Allows nillable values to be set to nil. This is useful when doing
28
- # an update and you want to clear out a value.
27
+ # Allows nullable values to be set to nil. This is useful when doing an
28
+ # update and you want to clear out a value. The logic also permits custom
29
+ # types (e.g., `Barcode`, `SourceId`) to be nullable if they are not
30
+ # required.
29
31
  def optional
30
- nullable || relaxed ? '.optional' : ''
32
+ return '.optional' if nullable ||
33
+ relaxed ||
34
+ (custom_type? && !required)
35
+
36
+ ''
31
37
  end
32
38
 
33
39
  def quote(item)
@@ -60,6 +66,11 @@ module Cocina
60
66
  "# Validation of this property is relaxed. See the openapi for full validation.\n"
61
67
  end
62
68
 
69
+ # dry-types-based types contain the word `Types` (e.g., `Types::String`), and custom types (e.g., `SourceId`) do not
70
+ def custom_type?
71
+ !dry_datatype(schema_doc).match?('Types')
72
+ end
73
+
63
74
  def dry_datatype(doc)
64
75
  return doc.name if doc.name.present? && schemas.include?(doc.name)
65
76
 
@@ -5,7 +5,6 @@ module Cocina
5
5
  # Class for generating from an openapi value
6
6
  class SchemaValue < SchemaBase
7
7
  def generate
8
- # optional has to come before default or the default value that gets set will be nil.
9
8
  if required && !relaxed
10
9
  "#{preamble}attribute :#{name.camelize(:lower)}, #{type}"
11
10
  else
@@ -16,6 +15,7 @@ module Cocina
16
15
  private
17
16
 
18
17
  def type
18
+ # optional has to come before default or the default value that gets set will be nil.
19
19
  "#{dry_datatype(schema_doc)}#{optional}#{default}#{enum}"
20
20
  end
21
21
 
@@ -7,7 +7,7 @@ module Cocina
7
7
  # Unique identifier in some other system. This is because a large proportion of what is deposited in SDR, historically and currently, are representations of objects that are also represented in other systems. For example, digitized paper and A/V collections have physical manifestations, and those physical objects are managed in systems that have their own identifiers. Similarly, books have barcodes, archival materials have collection numbers and physical locations, etc. The sourceId allows determining if an item has been deposited before and where to look for the original item if you're looking at its SDR representation. The format is: "namespace:identifier"
8
8
 
9
9
  # example: sul:PC0170_s3_Fiesta_Bowl_2012-01-02_210609_2026
10
- attribute? :sourceId, SourceId
10
+ attribute? :sourceId, SourceId.optional
11
11
  end
12
12
  end
13
13
  end
@@ -4,10 +4,10 @@ module Cocina
4
4
  module Models
5
5
  class Identification < Struct
6
6
  # A barcode
7
- attribute? :barcode, Barcode
7
+ attribute? :barcode, Barcode.optional
8
8
  attribute :catalogLinks, Types::Strict::Array.of(CatalogLink).default([].freeze)
9
9
  # Digital Object Identifier (https://www.doi.org)
10
- attribute? :doi, DOI
10
+ attribute? :doi, DOI.optional
11
11
  # Unique identifier in some other system. This is because a large proportion of what is deposited in SDR, historically and currently, are representations of objects that are also represented in other systems. For example, digitized paper and A/V collections have physical manifestations, and those physical objects are managed in systems that have their own identifiers. Similarly, books have barcodes, archival materials have collection numbers and physical locations, etc. The sourceId allows determining if an item has been deposited before and where to look for the original item if you're looking at its SDR representation. The format is: "namespace:identifier"
12
12
 
13
13
  # example: sul:PC0170_s3_Fiesta_Bowl_2012-01-02_210609_2026
@@ -20,7 +20,7 @@ module Cocina
20
20
  attribute? :standard, Standard.optional
21
21
  attribute :subject, Types::Strict::Array.of(DescriptiveValue).default([].freeze)
22
22
  # Stanford persistent URL associated with the related resource.
23
- attribute? :purl, Purl
23
+ attribute? :purl, Purl.optional
24
24
  attribute? :access, DescriptiveAccessMetadata.optional
25
25
  attribute :relatedResource, Types::Strict::Array.of(RelatedResource).default([].freeze)
26
26
  attribute? :adminMetadata, DescriptiveAdminMetadata.optional
@@ -5,7 +5,7 @@ module Cocina
5
5
  # Same as a Identification, but requires a sourceId and doesn't permit a DOI.
6
6
  class RequestIdentification < Struct
7
7
  # A barcode
8
- attribute? :barcode, Barcode
8
+ attribute? :barcode, Barcode.optional
9
9
  attribute :catalogLinks, Types::Strict::Array.of(CatalogLink).default([].freeze)
10
10
  # Unique identifier in some other system. This is because a large proportion of what is deposited in SDR, historically and currently, are representations of objects that are also represented in other systems. For example, digitized paper and A/V collections have physical manifestations, and those physical objects are managed in systems that have their own identifiers. Similarly, books have barcodes, archival materials have collection numbers and physical locations, etc. The sourceId allows determining if an item has been deposited before and where to look for the original item if you're looking at its SDR representation. The format is: "namespace:identifier"
11
11
 
@@ -19,22 +19,33 @@ module Cocina
19
19
  def validate
20
20
  return unless meets_preconditions?
21
21
 
22
+ validate_catalog('symphony')
23
+ validate_catalog('folio')
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :clazz, :attributes
29
+
30
+ def validate_catalog(catalog)
31
+ refresh_catalog_links = refresh_catalog_links_for(catalog)
32
+
22
33
  return if refresh_catalog_links.length <= MAX_REFRESH_CATALOG_LINKS
23
34
 
24
35
  raise ValidationError, "Multiple catalog links have 'refresh' property set to true " \
25
36
  "(only one allowed) #{refresh_catalog_links}"
26
37
  end
27
38
 
28
- private
29
-
30
- attr_reader :clazz, :attributes
39
+ def catalog_links
40
+ @catalog_links ||= Array(attributes.dig(:identification, :catalogLinks))
41
+ end
31
42
 
32
43
  def meets_preconditions?
33
- (dro? || collection?) && Array(attributes.dig(:identification, :catalogLinks)).any?
44
+ (dro? || collection?) && catalog_links.any?
34
45
  end
35
46
 
36
- def refresh_catalog_links
37
- attributes.dig(:identification, :catalogLinks).select { |catalog_link| catalog_link[:refresh] }
47
+ def refresh_catalog_links_for(catalog)
48
+ catalog_links.select { |catalog_link| catalog_link[:catalog] == catalog && catalog_link[:refresh] }
38
49
  end
39
50
 
40
51
  def dro?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocina
4
4
  module Models
5
- VERSION = '0.87.0'
5
+ VERSION = '0.88.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.87.0
4
+ version: 0.88.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-14 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -531,7 +531,7 @@ homepage: https://github.com/sul-dlss/cocina-models
531
531
  licenses: []
532
532
  metadata:
533
533
  rubygems_mfa_required: 'true'
534
- post_install_message:
534
+ post_install_message:
535
535
  rdoc_options: []
536
536
  require_paths:
537
537
  - lib
@@ -547,7 +547,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
547
547
  version: '0'
548
548
  requirements: []
549
549
  rubygems_version: 3.3.7
550
- signing_key:
550
+ signing_key:
551
551
  specification_version: 4
552
552
  summary: Data models for the SDR
553
553
  test_files: []