cocina-models 0.17.0 → 0.18.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: 6e23b0e03fa39eb46ba0dd2f99befd2a1eea00a1294c44da2717892ede74a2c3
4
- data.tar.gz: 1149930ef7b568cdd28b96447148d58dd9e83846133a7316a317c179dbd6330a
3
+ metadata.gz: eb44299e9e86c9fdde5589710db813e3691add7bbf59b14d34ab6edf89cffa9b
4
+ data.tar.gz: a63852fd6c5a8369ff49236b4fea55504dfaa3e0944fcc74e6da03605031e504
5
5
  SHA512:
6
- metadata.gz: 0cc112f49830c1b00a20fcad1c15d21e9563ba09fdf84406d55d5cbfb9e73a9612e7056b62d63629841b1c690f9fa06541e2a3a2c37d6f8f5995edc52ffa6342
7
- data.tar.gz: cc12548903b6b5b1befc9a236611473f30af7323994f36de49822ad31f318770d1ecc8070344552b19019984b3899c2073bacead487ba9670123c17460873583
6
+ metadata.gz: be279159d4b042bc5265db234d6f938bcecfafd5240c969a5f5f77af6acf7a00aadfad6076110f3674596f7354b435c526de2559067fbd53539907e209c28369
7
+ data.tar.gz: 1bab7879c6051415a51226b5abd983f38fdc883dd93d5053c39240a51943e1ca4baae19034929861edc4579fa7fdca0b4b61bd4a08aab5539ebd7bb45ee520b6
data/.rubocop.yml CHANGED
@@ -18,4 +18,4 @@ RSpec/MultipleExpectations:
18
18
  Enabled: false
19
19
 
20
20
  RSpec/ExampleLength:
21
- Max: 12
21
+ Max: 15
data/lib/cocina/models.rb CHANGED
@@ -12,6 +12,10 @@ class CocinaModelsInflector < Zeitwerk::Inflector
12
12
  case basename
13
13
  when 'dro'
14
14
  'DRO'
15
+ when 'dro_builder'
16
+ 'DROBuilder'
17
+ when 'request_dro'
18
+ 'RequestDRO'
15
19
  when 'version'
16
20
  'VERSION'
17
21
  else
@@ -67,18 +67,7 @@ module Cocina
67
67
  attribute(:structural, Structural.default { Structural.new })
68
68
 
69
69
  def self.from_dynamic(dyn)
70
- params = {
71
- externalIdentifier: dyn['externalIdentifier'],
72
- type: dyn['type'],
73
- label: dyn['label'],
74
- version: dyn['version']
75
- }
76
-
77
- # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
78
- params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
79
- params[:description] = Description.from_dynamic(dyn.fetch('description'))
80
- params[:identification] = Identification.from_dynamic(dyn['identification']) if dyn['identification']
81
- Collection.new(params)
70
+ CollectionBuilder.build(self, dyn)
82
71
  end
83
72
 
84
73
  def self.from_json(json)
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # This creates a Collection or a RequestCollection from dynamic attributes
6
+ class CollectionBuilder
7
+ # @return [Collection,RequestCollection]
8
+ # rubocop:disable Metrics/MethodLength
9
+ def self.build(klass, dyn)
10
+ params = {
11
+ type: dyn['type'],
12
+ label: dyn['label'],
13
+ version: dyn['version'],
14
+ description: Description.from_dynamic(dyn.fetch('description'))
15
+ }
16
+ params[:externalIdentifier] = dyn['externalIdentifier'] if needs_id?(klass)
17
+ # params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
18
+ if dyn['administrative']
19
+ params[:administrative] = Collection::Administrative
20
+ .from_dynamic(dyn['administrative'])
21
+ end
22
+ if dyn['identification']
23
+ params[:identification] = Collection::Identification
24
+ .from_dynamic(dyn['identification'])
25
+ end
26
+ klass.new(params)
27
+ end
28
+ # rubocop:enable Metrics/MethodLength
29
+
30
+ def self.needs_id?(klass)
31
+ klass.attribute_names.include?(:externalIdentifier)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -90,23 +90,9 @@ module Cocina
90
90
  attribute(:identification, Identification.default { Identification.new })
91
91
  attribute(:structural, Structural.default { Structural.new })
92
92
 
93
- # rubocop:disable Metrics/AbcSize
94
93
  def self.from_dynamic(dyn)
95
- params = {
96
- externalIdentifier: dyn['externalIdentifier'],
97
- type: dyn['type'],
98
- label: dyn['label'],
99
- version: dyn['version']
100
- }
101
-
102
- params[:access] = Access.from_dynamic(dyn['access']) if dyn['access']
103
- params[:administrative] = Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
104
- params[:description] = Description.from_dynamic(dyn.fetch('description'))
105
- params[:identification] = Identification.from_dynamic(dyn['identification']) if dyn['identification']
106
- params[:structural] = Structural.from_dynamic(dyn['structural']) if dyn['structural']
107
- DRO.new(params)
94
+ DROBuilder.build(self, dyn)
108
95
  end
109
- # rubocop:enable Metrics/AbcSize
110
96
 
111
97
  def self.from_json(json)
112
98
  from_dynamic(JSON.parse(json))
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # This creates a DRO or a RequestDRO from dynamic attributes
6
+ class DROBuilder
7
+ # @return [DRO,RequestDRO]
8
+ # rubocop:disable Metrics/AbcSize
9
+ def self.build(klass, dyn)
10
+ params = {
11
+ type: dyn['type'],
12
+ label: dyn['label'],
13
+ version: dyn['version'],
14
+ description: Description.from_dynamic(dyn.fetch('description'))
15
+ }
16
+ params[:externalIdentifier] = dyn['externalIdentifier'] if needs_id?(klass)
17
+
18
+ params[:access] = DRO::Access.from_dynamic(dyn['access']) if dyn['access']
19
+ params[:administrative] = DRO::Administrative.from_dynamic(dyn['administrative']) if dyn['administrative']
20
+ params[:identification] = DRO::Identification.from_dynamic(dyn['identification']) if dyn['identification']
21
+ params[:structural] = DRO::Structural.from_dynamic(dyn['structural']) if dyn['structural']
22
+ klass.new(params)
23
+ end
24
+ # rubocop:enable Metrics/AbcSize
25
+
26
+ def self.needs_id?(klass)
27
+ klass.attribute_names.include?(:externalIdentifier)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # A request to create a digital repository collection.
6
+ # This is the same as Collection, except it doesn't have externalIdentifier.
7
+ # See http://sul-dlss.github.io/cocina-models/maps/Collection.json
8
+ class RequestCollection < Dry::Struct
9
+ attribute :type, Types::String.enum(*Collection::TYPES)
10
+ attribute :label, Types::Strict::String
11
+ attribute :version, Types::Coercible::Integer
12
+ attribute(:access, Collection::Access.default { Collection::Access.new })
13
+ attribute(:administrative, Collection::Administrative.default { Collection::Administrative.new })
14
+ # Allowing description to be omittable for now (until rolled out to consumers),
15
+ # but I think it's actually required for every DRO
16
+ attribute :description, Description.optional.default(nil)
17
+ attribute(:identification, Collection::Identification.default { Collection::Identification.new })
18
+ attribute(:structural, Collection::Structural.default { Collection::Structural.new })
19
+
20
+ def self.from_dynamic(dyn)
21
+ CollectionBuilder.build(self, dyn)
22
+ end
23
+
24
+ def self.from_json(json)
25
+ from_dynamic(JSON.parse(json))
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocina
4
+ module Models
5
+ # A Request to create a digital repository object. (to create) object.
6
+ # This is same as a DRO, but without externalIdentifier (as that wouldn't have been created yet)
7
+ # See http://sul-dlss.github.io/cocina-models/maps/DRO.json
8
+ class RequestDRO < Dry::Struct
9
+ attribute :type, Types::String.enum(*DRO::TYPES)
10
+ attribute :label, Types::Strict::String
11
+ attribute :version, Types::Coercible::Integer
12
+ attribute(:access, DRO::Access.default { DRO::Access.new })
13
+ attribute(:administrative, DRO::Administrative.default { DRO::Administrative.new })
14
+ # Allowing description to be omittable for now (until rolled out to consumers),
15
+ # but I think it's actually required for every DRO
16
+ attribute :description, Description.optional.default(nil)
17
+ attribute(:identification, DRO::Identification.default { DRO::Identification.new })
18
+ attribute(:structural, DRO::Structural.default { DRO::Structural.new })
19
+
20
+ def self.from_dynamic(dyn)
21
+ DROBuilder.build(self, dyn)
22
+ end
23
+
24
+ def self.from_json(json)
25
+ from_dynamic(JSON.parse(json))
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cocina
4
4
  module Models
5
- VERSION = '0.17.0'
5
+ VERSION = '0.18.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -180,11 +180,15 @@ files:
180
180
  - lib/cocina/models/catalog_link.rb
181
181
  - lib/cocina/models/checkable.rb
182
182
  - lib/cocina/models/collection.rb
183
+ - lib/cocina/models/collection_builder.rb
183
184
  - lib/cocina/models/description.rb
184
185
  - lib/cocina/models/dro.rb
186
+ - lib/cocina/models/dro_builder.rb
185
187
  - lib/cocina/models/file.rb
186
188
  - lib/cocina/models/file_set.rb
187
189
  - lib/cocina/models/release_tag.rb
190
+ - lib/cocina/models/request_collection.rb
191
+ - lib/cocina/models/request_dro.rb
188
192
  - lib/cocina/models/types.rb
189
193
  - lib/cocina/models/version.rb
190
194
  - lib/cocina/models/vocab.rb