cocina-models 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/cocina/models.rb +4 -0
- data/lib/cocina/models/collection.rb +1 -12
- data/lib/cocina/models/collection_builder.rb +35 -0
- data/lib/cocina/models/dro.rb +1 -15
- data/lib/cocina/models/dro_builder.rb +31 -0
- data/lib/cocina/models/request_collection.rb +29 -0
- data/lib/cocina/models/request_dro.rb +29 -0
- data/lib/cocina/models/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb44299e9e86c9fdde5589710db813e3691add7bbf59b14d34ab6edf89cffa9b
|
4
|
+
data.tar.gz: a63852fd6c5a8369ff49236b4fea55504dfaa3e0944fcc74e6da03605031e504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be279159d4b042bc5265db234d6f938bcecfafd5240c969a5f5f77af6acf7a00aadfad6076110f3674596f7354b435c526de2559067fbd53539907e209c28369
|
7
|
+
data.tar.gz: 1bab7879c6051415a51226b5abd983f38fdc883dd93d5053c39240a51943e1ca4baae19034929861edc4579fa7fdca0b4b61bd4a08aab5539ebd7bb45ee520b6
|
data/.rubocop.yml
CHANGED
data/lib/cocina/models.rb
CHANGED
@@ -67,18 +67,7 @@ module Cocina
|
|
67
67
|
attribute(:structural, Structural.default { Structural.new })
|
68
68
|
|
69
69
|
def self.from_dynamic(dyn)
|
70
|
-
|
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
|
data/lib/cocina/models/dro.rb
CHANGED
@@ -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
|
-
|
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
|
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.
|
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
|